How to show layout on the bottom of ListView - android

I have a layout xml like below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:maxWidth="71dip"
android:src="#drawable/logo_top" >
</ImageView>
<ImageView
android:id="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:adjustViewBounds="false"
android:clickable="true"
android:maxHeight="70dip"
android:src="#drawable/registeration_title" >
</ImageView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" >
</TextView>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/linearframe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/informationFrame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" >
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:src="#drawable/registeration_info1" />
<TextView
android:id="#+id/IDNumberTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="7dip"
android:layout_marginLeft="26dip"
android:text="TextView"
android:textColor="#drawable/textgreen" />
<TextView
android:id="#+id/EnableDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="7dip"
android:layout_marginLeft="140dip"
android:text="TextView"
android:textColor="#drawable/textgreen" />
</FrameLayout>
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/linearframe"
android:text=" " />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:layout_centerHorizontal="true"
android:src="#drawable/buy_in_60" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="#id/imageView5"
android:layout_alignRight="#id/imageView5"
android:layout_below="#id/imageView5" >
</ListView>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<FrameLayout
android:id="#+id/frameLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/listView1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="79dp" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/registeration_info2" />
<TextView
android:id="#+id/VersionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="48dip"
android:text="Version: 1.0"
android:textColor="#drawable/darkgreen" />
</FrameLayout>
<TextView
android:id="#+id/RevisionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/frameLayout2"
android:layout_centerHorizontal="true"
android:layout_marginLeft="79dp"
android:text="Revision: 16"
android:textColor="#drawable/darkgreen" />
</RelativeLayout>
some layouts below the ListView in the xml will disappear on the screen
and I tried to put the ListView and other layouts below the ListView into a scrollView
but the ListView will shrink, it looks too small, so i remove the ScrollView,
how should i do to let them appear on the screen without ScrollView?

You need to set Weight to your layouts like this way..
like you can set ListView Weight is= 0.80 and Bottom View is = 0.20 make sure parent Linear layout Weight sum is = 1.
You can see this is my xml file having List View (80% screen) and bottom Bar layout for Google Ads (almost 20% screen).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:id="#+id/layVrt"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_weight="0.72"
android:weightSum="1">
<ListView
android:layout_width="match_parent"
android:id="#+id/listViewGame"
android:textFilterEnabled="true"
android:layout_height="350dp"
android:layout_weight="0.73"></ListView>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_weight="0.20"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corners_white"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_height="50dp"
android:layout_marginBottom="3dp"
android:id="#+id/layoutAdMobList">
</LinearLayout>
</LinearLayout>
so this will be the output..

Or you can try something like 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" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_bar" >
</ListView>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bottom_bar"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/slider_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/bottom_toggle_button" />
<ToggleButton
android:id="#+id/list_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/bottom_left_button" />
<ToggleButton
android:id="#+id/map_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/bottom_right_button" />
</LinearLayout>
</RelativeLayout>
Place everything inside a RelativeLayout and use android:layout_above="#+id/bottom_bar" on the ListView

Related

Listview not scrolling totally android

I have a ListView that is not scrolling for complete. I inserted 20 items, but the listview is scrolling until the item 15º.
My Layout XML code here :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/checklistview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
</LinearLayout>
Here a screenshot:
I don't understand WHY this is happening. For example, If I put 6 items, the 6º item is not show and I can't scroll the listview. Missing something?
The problem is in your layout xml
change it with this one:
<?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" >
<RelativeLayout
android:id="#+id/topPart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<ListView
android:id="#+id/checklistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/topPart" >
</ListView>
</RelativeLayout>
You should not add multiple enties below each other using android:layout_height="fill_parent" or "match_parent" (which is the same) in the same layout as you do in the LinearLayout.
Make it another RelativeLayout with using layout_below, layout_parentOnBottom and other options or place everything into one huge relative layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/toppart"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/sky" >
<TextView
android:id="#+id/tvQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical|center_horizontal"
android:scrollbars="none"
android:text="#string/QuoteTeste"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="14pt" />
<Space
android:id="#+id/espaco"
android:layout_width="wrap_content"
android:layout_height="30dp" >
</Space>
<TextView
android:id="#+id/tvAutor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvQuote"
android:layout_below="#+id/tvQuote"
android:layout_marginTop="22dp"
android:text="(Carlos Drummond)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bottompart"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_below="#+id/toppart"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/checklistview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>

ListView are increase relativelayout size

I have a listview in inside a RelativeLayout. The size of my relativelayour change according the size of my listview (number of rows). If it has only two rows, the relative layout stays larger. If it has more rows, the relative stays smaller.
This happen only in small devices.
What do I do?
EDIT: CODE BELOW
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_cinza_transparente_98_porcento"
android:orientation="vertical"
tools:context=".AdicionarMarcaModeloActivity" >
<LinearLayout
style="#style/..."
android:layout_width="match_parent"
android:background="#color/cinza_escuro"
android:orientation="vertical" >
<RelativeLayout
style="#style/..."
android:orientation="vertical" >
<TextView
android:id="#+id/labelCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Marca"
android:textColor="#android:color/white"
android:textSize="22sp" />
<ImageView
android:id="#+id/imgCloseMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:src="#drawable/bt_close" />
</RelativeLayout>
<RelativeLayout
style="#style/..."
android:layout_width="match_parent"
android:background="#color/branco_gelo"
android:orientation="vertical" >
<TextView
android:id="#+id/labelSubCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="SELECIONE A MARCA DO SEU VEÍCULO"
android:textColor="#color/cinza_escuro_fontes_cabecalho" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
style="#style/..."
android:layout_width="match_parent"
android:orientation="horizontal" >
<ListView
android:id="#+id/lvMarcaModelo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#drawable/line" >
</ListView>
</RelativeLayout>
// Try this way,hope this will help you to solve your problem...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/labelCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Marca"
android:textColor="#android:color/white"
android:layout_gravity="center_horizontal"
android:textSize="22sp" />
<ImageView
android:id="#+id/imgCloseMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:src="#drawable/ic_launcher"
android:layout_marginTop="5dp"/>
<TextView
android:id="#+id/labelSubCabecalhoMarcaModelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="SELECIONE A MARCA DO SEU VEÍCULO"
android:layout_marginTop="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="5dp">
<ListView
android:id="#+id/lvMarcaModelo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#drawable/line" >
</ListView>
</LinearLayout>
</LinearLayout>

Vertical Linear Imageview goes at the bottom

i am working on a layout with 3 buttons and an image view i call the imageview as the first child of the parent however when i build it on actual device the imageview goes down after the buttons... really weird....
heres the xml file:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/111"
android:visibility="visible" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/222"
android:visibility="visible"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_medium"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/highscores_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/highscore_btn"
android:visibility="visible" />
<Button
android:id="#+id/more_apps_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_medium"
android:background="#drawable/333"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
is this because of the size of the imageview? it is really large so i put it in xxhdpi folder so it will be reduced. any thoughts? thanks
// try this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView
android:id="#+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/111"
android:visibility="visible" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/222"
android:visibility="visible"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_medium"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/highscores_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/highscore_btn"
android:visibility="visible" />
<Button
android:id="#+id/more_apps_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_medium"
android:background="#drawable/333"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</FrameLayout>

Complex android layout (overlapping, left/right align, center align)

I have to create the following layout on an Android device:
The requirements are as follows:
First layout which occupies the whole screen (fill_parent);
Second (at the bottom of the screen) overlays the first one and has the following formats:
3 columns;
occupies the whole screen width;
arrows are aligned left and right sides, and text area is resized based on screen width;
I've tried numerous things, but since I'm new to the Android world, I had no success yet.
Here is what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="100"
android:id="#+id/RootView">
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:id="#+id/mapImageView" />
<LinearLayout
android:id="#+id/bottomArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="#+id/adsArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<ImageButton
android:src="#drawable/leftArrow"
android:id="#+id/btnPrev"
android:layout_alignParentRight="true"
android:layout_marginLeft="0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some summary text" />
</LinearLayout>
<ImageButton
android:src="#drawable/rightArrow"
android:layout_alignParentRight="true"
android:layout_marginRight="0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnNext" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
but the text doesn't seem to be center aligned, nor resized to the screen width:
Does someone has a clue?
Thanks.
Use this code for your required layout...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linear2" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<RelativeLayout
android:id="#+id/linear2"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<ImageButton
android:id="#+id/leftButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/rightButton1"
android:layout_toRightOf="#+id/leftButton1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some summary text" />
</LinearLayout>
<ImageButton
android:id="#+id/rightButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
Please find the code below. Also, do not use multiple viewgroup for simple layout solution.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RootView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/mapImageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#android:drawable/ic_menu_gallery" />
<RelativeLayout
android:id="#+id/adsArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ImageButton
android:id="#+id/btnPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/leftArrow" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some summary text" />
</LinearLayout>
<ImageButton
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/rightArrow" />
</RelativeLayout>
</RelativeLayout>

Fill RelativeLayout parent with LinearLayout child

This seems simple but I've exhausted my Google search patience.
I have a RelativeLayout that has two sub LinearLayouts side-by-side and I want them both to vertically fill the parent, no matter the height of the two LinearLayouts. This is being used as a ListView row and the content under #id/item_left is generally shorter than the one on the right.
The background drawable doesn't fill the entire row.
Any ideas on making both sides fill?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/item_left"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="2dp"
android:paddingLeft="2dp"
android:background="#drawable/item_left"
android:orientation="vertical">
<TextView android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_left_text"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/item_right_background"
android:layout_toRightOf="#id/item_left">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="Row1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="Row2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="Row3" />
</LinearLayout>
</RelativeLayout>
try this code .... sorry but I changed the color to so the impact when you will change the text of first TextView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="fill_parent"
android:background="#ffffffff" android:weightSum="1">
<LinearLayout android:id="#+id/item_left"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:paddingRight="2dp" android:paddingLeft="2dp"
android:background="#ff0000ff" android:orientation="vertical" >
<TextView android:id="#+id/time" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff555555"
android:text="sdfdsf s ada d a asd sad sad" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="match_parent" android:orientation="vertical"
android:background="#ffff0000"
android:layout_weight="1" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff555555"
android:text="Row1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff00ff00"
android:text="Row2" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff00ff00"
android:text="Row3" />
</LinearLayout>
</LinearLayout>
<?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" >
<LinearLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FF0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="helloooooooooooooo" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/layout1"
android:background="#0000FF"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row3" />
</LinearLayout>
</RelativeLayout>

Categories

Resources