I have this XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/blanco"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/verde_us" >
<ImageView
android:id="#+id/detalle_imagen_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:src="#drawable/icon_map" />
<View
android:id="#+id/View02"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#color/blanco" />
<TextView
android:id="#+id/text_nombre_empresa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="#string/text_noticias"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/blanco" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</LinearLayout>
But when I run the app the output is other.
Any help? Thanks!
I want the tabs below the text that says "Ahumadero" In the XML
Then stop using action bar tabs. Use some other sort of tabbed indicator for your ViewPager, one where you control the position by placing it in the LinearLayout yourself. There are many open source implementations, such as PagerSlidingTabStrip.
Related
I'm trying to implement a landscape layout for my Android project. I had it semi working previously, other than that "leftRightLinear" was being overlapped slightly by the button layout at the bottom.
Since trying to fix that problem, I've given up and rolled back to my working version, which is no longer working and I can't figure out why.
The contents of pendingLinear and semesterLinear aren't displaying.
Any ideas?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainLinear"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/leftRightLinear"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="#+id/leftLinear"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" >
<TextView
android:text="#string/pendingUnits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="#+id/pendingScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="0dp"
android:background="#drawable/border">
<LinearLayout
android:id="#+id/pendingLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/rightLinear"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" >
<TextView
android:text="#string/semesters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="#+id/semesterScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="0dp"
android:background="#drawable/border">
<LinearLayout
android:id="#+id/semesterLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/border_confirm"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/saveButtonSemester"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:onClick="clickSave"
android:text="#string/button_save"
/>
<Button
android:id="#+id/confirmBtn"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/confirm"
android:onClick="clickConfirm"
/>
</LinearLayout>
The contents of pendingLinear and semesterLinear aren't displaying
It's because both of your ScrollView are set android:layout_height="0dp". Change them to android:layout_height="fill_content", like so:
<ScrollView
android:id="#+id/pendingScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="fill_parent">
About this problem
"leftRightLinear" was being overlapped slightly by the button layout at the bottom
To let leftRightLinear sit above the button layout, first give the button layout a name
<LinearLayout
android:id="#+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
Then add this attribute to leftRightLinear, android:layout_above="#+id/buttonLayout", like so:
<LinearLayout
android:id="#+id/leftRightLinear"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/buttonLayout"
android:layout_alignParentTop="true" >
Here's the result: (Background of the left scrollview is set black)
pendingLinear and semesterLinear do not have any contents so there is nothing to be shown, they are there - they exist - they are just empty.
Are you adding contents to them dynamically ? if so I'd like to look at the code otherwise try inserting a TextView inside one of them (or both) to confirm that they are being shown.
<TabHost
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
// --------------------------- Here I got warning -------------------------
<LinearLayout
android:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
// --------------------------------------------------------------------------
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white" >
</ListView>
<LinearLayout
android:id="#+id/text_entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal" >
<EditText
android:id="#+id/txt_inputText"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="#string/enter_text"
android:inputType="text" />
<Button
android:id="#+id/btn_Send"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/send" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" >
</TabWidget>
</LinearLayout>
</TabHost>
How to solve this warning ? I can't find any solution. Any help will be appreciated.
I am not sure what exactly you are trying to accomplish, but you can get rid of the warning by moving FrameLayout content to a separate file and add it back to your TabHost by using <include> tag.
A possible version could look something like this:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<include layout="#layout/tab_chat_list" />
</FrameLayout>
</LinearLayout>
</TabHost>
And tab_chat_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white" >
</ListView>
<LinearLayout
android:id="#+id/text_entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal" >
<EditText
android:id="#+id/txt_inputText"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="#string/enter_text"
android:inputType="text" />
<Button
android:id="#+id/btn_Send"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/send" />
</LinearLayout>
</LinearLayout>
</merge>
Hope this helps.
Update
I noticed that some people are suggesting to remove FrameLayout. Although, that could have solved the problem in other cases, TabHost needs TabWidget and FrameLayout to function correctly.
The warning you are getting is this one:
UselessParent
Summary: Checks whether a parent layout can be removed.
Priority: 2 / 10 Severity: Warning Category: Performance
A layout with children that has no siblings, is not a scrollview or a
root layout, and does not have a background, can be removed and have
its children moved directly into the parent for a flatter and more
efficient layout hierarchy.
It can be turned off in Lint.
Update: I missed that tabhost requires a framelayout to work. Disabling the warning or going with shoe rat's solution should still fix the problem. (ignore paragraph below)
Assuming you don't need the FrameLayout (i.e. to add stuff dynamically), you can try removing it and adjusting the LinearLayout accordingly:
<LinearLayout
ndroid:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="visible" >
Take a look at the following layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rlInner"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text" />
</RelativeLayout>
</LinearLayout>
There is nothing wrong with it and any activity using this layout will run without a problem. But eclipse will give you a warning:
This RelativeLayout layout or its LinearLayout parent is useless
As you can see, I only need one of the two container layouts above. Adding the RelativeLayout with id="rlInner" does nothing to change the layout. When eclipse finds a scenario like this, it gives you an appropriate warning to indicate the redundancy.
In your scenario, you can lose the FrameLayout altogether without disturbing the layout. And this would fix the warning.
Add an ID to the parent linear layout.
It's useless because the parent linear layout doesn't have an id. It means it would be difficult or impossible to add stuff in code outside the linear layout where you got the error.
I have:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activityLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ColorViewerActivity" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content">
// skip it
</TabHost>
<TextView
android:id="#+id/decDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/tabhost"
android:layout_centerHorizontal="true"
android:gravity="center_vertical|center_horizontal"
android:text="222"
android:textSize="19sp" />
<LinearLayout
android:id="#+id/panelLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="1dip"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="#+id/hexDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/decDescription"
android:layout_alignRight="#+id/panelLayout"
android:layout_below="#android:id/tabhost"
android:text="111"
android:textSize="14sp" />
</RelativeLayout>
If I put the last TextView (id=hexDescription) before penult LinearLayout (id=panelLayout) I get the exception. From LogCat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{ com.gmail.leonidandand.colorviewer/com.gmail.leonidandand.colorviewer.ColorViewerActivity}:
java.lang.ClassCastException: android.widget.LinearLayout
What could be the problem?
Sorry for my English.
Thanks
It does because you are indicating that it should be positioned relative to the LinearLayout. So you need to declare it after the elements that you want to position it to. If you aren't declaring
android:layout_alignRight="#+id/panelLayout"
in your hex TextView then it doesn't matter. This is because when its drawing the layout it sees that property and it can't find the id of which to position it relative to since it hasn't yet drawn that view
try re-arranging the stuff below
android:layout_alignBottom="#+id/decDescription"
android:layout_alignRight="#+id/panelLayout"
android:layout_below="#android:id/tabhost"
The error might take place because you are aligning it in the bottom of decDescription AND below the tabhost
Tabhost requires TabWidget with an id. This is what lint warned when i used your xml layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activityLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ColorViewerActivity" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</TabHost>
<TextView
android:id="#+id/decDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/tabhost"
android:layout_centerHorizontal="true"
android:gravity="center_vertical|center_horizontal"
android:text="222"
android:textSize="19sp" />
<LinearLayout
android:id="#+id/panelLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="1dip"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="#+id/hexDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/decDescription"
android:layout_alignRight="#+id/panelLayout"
android:layout_below="#android:id/tabhost"
android:text="111"
android:textSize="14sp" />
</RelativeLayout>
TabHost has a tabWidget and a FrameLayout.
Snap shot captured from graphical layout
Working example at http://www.androidhive.info/2011/08/android-tab-layout-tutorial/
I have a problem to layout my view.
I want the "buttonsLayout" to dock at the bottom of the view. That is no problem, but my "buttonsLayout" overlays the "pager". I want that the "pager" stops, where the "buttonsLayout" begins.
I have read so many posts, but nothing helps. What is wrong ?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/gray" >
</android.support.v4.view.ViewPager>
<RelativeLayout
android:id="#+id/buttonsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Left" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Right" />
</RelativeLayout>
</RelativeLayout>
Add android:layout_above = "#+id/buttonsLayout" to your pager layout. So pager will never overlay buttons.
P.S. I cant see one more closing RelativeLayout tag in your xml...
Good day, I have an Activity which contains 4 fragments. The Activity has a footer which I use to switch between these fragment views. Now in one of my fragments, i have some widgets and the last widget is a ListView. The trouble am having is, the last 2 entries in the Listview are not displaying correctly! they are obscured by the footer. I have set my LayoutParameters for both the width and height of the Listview to FILL_PARENT. but its not working. Any idea how i can solve this? Thanks in advance.
My Layout is :
for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="#+id/line_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_marginLeft="5dp" android:focusable="true"
android:layout_marginTop="8dp" android:text="#string/line_graph" android:background="#drawable/temp_left_button" />
<Button android:id="#+id/bar_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignBaseline="#+id/line_button_id"
android:layout_alignBottom="#+id/line_button_id" android:focusable="true"
android:layout_alignParentRight="true" android:layout_marginRight="5dp"
android:text="#string/bar_graph" android:background="#drawable/temp_right_button"></Button>"
<FrameLayout
android:id="#+id/graph_framelayout_id"
android:layout_width="fill_parent"
android:layout_height="280dp"
android:layout_below="#id/line_button_id"
android:padding="4dp"
android:layout_margin="4dp"
android:background="#drawable/rounded_date_filter">
</FrameLayout>
<!-- first cell information, dashboard -->
<LinearLayout
android:id="#+id/row1_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_below="#id/graph_framelayout_id"
android:orientation="horizontal"
android:clickable="true"
android:background="#drawable/rounded_table_row">
<TextView
android:id="#+id/dashboard_datefrom_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="01 may 2012"/>
<ImageView
android:id="#+id/dashboard_image_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_action_search"/>
<TextView
android:id="#+id/dashboard_dateto_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:text="01 sept 2012"/>
</LinearLayout>
<!-- accounts overview listview -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row1_id"
android:layout_margin="4dp"
android:orientation="vertical"
android:background="#drawable/rounded_date_filter">
<TextView
android:id="#+id/list_text_header_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="#string/data_grid_text_header_day"
android:background="#drawable/text_header">
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</RelativeLayout>
and for the Activity i have this:
<
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/fragment_container_id"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<include layout="#layout/footer"></include>"
</RelativeLayout>
i replace the fragments with in the framelayout of the Activity
What Layout are you using in your Fragment, this surely won't happen if you use RelativeLayout and set above attribute to your ListView like this :
Try to add this into FrameLayout in your Activity layout.
android:layout_above="#+id/footer"