So I am trying to align my listviews under my textview headers. However, everything I have changed from changing the layouts or gravity or anything like that seems to now put the listviews directly under their respective header.
Here is what it looks like right now:
Here is the XML that has the headers
<?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">
<!--Header aligned to top -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/header"
android:gravity="center"
android:background="#FC9">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Drive_Number"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#000"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Drive_Distance"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#000"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Drive_Time"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#000"
android:layout_weight="1"
android:gravity="center_horizontal"/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="#005"
android:layout_below="#+id/header"
android:id="#+id/scrollableContents">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
Here is the XML that has the listviews:
<?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textSize="20sp"
android:textColor="#CCCCCC"
android:text="Medium Text"
android:id="#+id/Drive_Number_List"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textSize="20sp"
android:textColor="#CCCCCC"
android:text="Medium Text"
android:id="#+id/Drive_Distance_List"
android:layout_weight="1"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textSize="20sp"
android:textColor="#CCCCCC"
android:text="Medium Text"
android:id="#+id/Drive_Time_List"
android:layout_weight="1"
android:gravity="center_horizontal"/>
</LinearLayout>
It seems there are two ways you can achieve the "alignment" that you want.
Align the headers as per the listview items as shown in picture:
Use LinearLayout for headers. Divide the three textviews (in header) equally by using android:layout_weight = 1 and android:layout_width="0dp" for all, and set gravity="left" for the leftmost textview, gravity="right" for rightmost textview and gravity="center_horizontal" for middle one.
Keep everything center aligned in its own one-third of total screen width:
Use LinearLayout for headers as well as listview items. Divide using layout weights and 0dp width as above. Use gravity="center_horizontal" for all items
Note: use the "gravity" attribute, not "layout_gravity"
Try this, you can change the padding if you want
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Header aligned to top -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/header"
android:background="#FC9"
android:orientation="horizontal">
<TextView
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/Drive_Number"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#000"/>
<TextView
android:gravity="center"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/Drive_Distance"
android:layout_toRightOf="#+id/Drive_Number"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#000"/>
<TextView
android:paddingRight="10dp"
android:paddingEnd="10dp"
android:gravity="right"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/Drive_Time"
android:layout_toRightOf="#+id/Drive_Distance"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#000"/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="#005"
android:layout_below="#+id/header"
android:id="#+id/scrollableContents">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Related
I go nuts on that layout. So here's what I'm trying to achieve. A simple layout having a label (TextView) or edit field (EditText) on the left side and a button on the right side. I want all labels and all buttons vertically adjusted - meaning all buttons of the same width and all labels too.
But how to do this? I tried a LinearLayout with vertical orientation and each line as another LinearLayout with horizontal orientation and inside that the label has a layout_weight of 8 and the button is 1. But still this does not guarantee what I want!
This is the current result. You can see that the buttons are not nicely aligned.
This is my layout:
Here's the XML:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:hint="test_test_blabla"
android:layout_weight="8"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="left"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/action_scan"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_weight="1"
android:layout_gravity="right"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="17:35"
android:layout_weight="8"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="left"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/action_pick_time"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_weight="1"
android:layout_gravity="right"
/>
</LinearLayout>
</LinearLayout>
Using a RelativeLayout you can achieve the desired layout as:
<?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">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView"
android:layout_toLeftOf="#+id/button"
android:fontFamily="sans-serif-thin"
android:hint="test_test_blabla"
android:textSize="24sp"/>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/textView"
android:fontFamily="sans-serif-thin"
android:hint="Scan"
android:textSize="24sp"/>
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText"
android:layout_toLeftOf="#+id/button2"
android:fontFamily="sans-serif-thin"
android:text="17:35"
android:textSize="24sp"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/button"
android:fontFamily="sans-serif-thin"
android:hint="Pick Time"
android:textSize="24sp"/>
</RelativeLayout>
The key layout attribute used to match the size is android:layout_alignRight="#+id/textView" on the first EditText referencing the TextView just below.
Result:
According to people's advise, I used the TableLayout. But still the label (EditText) is not using the whole space til the button.
That's the XML:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:hint="test_test_blabla"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="left"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/action_scan"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="right"
/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="17:35"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="left"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/action_pick_time"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="right"
/>
</TableRow>
<TableRow>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:hint="#string/hint_car_location_address"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="left"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/action_gps"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:layout_gravity="right"
/>
</TableRow>
</TableLayout>
Edit:
try RelativeLayout
something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:columnCount="2">
<EditText
android:id="#android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#android:id/button1"
android:text="test"/>
<Button
android:id="#android:id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingLeft="28dp"
android:paddingRight="28dp"
android:text="set"
/>
<TextView
android:id="#android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#android:id/button1"
android:layout_alignBottom="#android:id/button2"
android:layout_below="#android:id/button1"
android:gravity="center_vertical"
android:text="some test"/>
<Button
android:id="#android:id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/button1"
android:layout_alignLeft="#android:id/button1"
android:layout_alignRight="#android:id/button1"
android:text="Scan"
/>
</RelativeLayout>
5+ years later...OP is probably an expert in android xml by now. Nevertheless, to help with the question, linear layout is doable. I've added another linear layout to contain all the rows so that the margins can be adjust in this additional layout.
When weight sum is used, the corresponding variable (width / height) has to be 0dp so that it can be adjust accordingly.
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="9">
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"
android:fontFamily="sans-serif-thin"
android:hint="test_test_blabla"
android:textSize="24sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="sans-serif-thin"
android:hint="#string/action_scan"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal"
android:weightSum="9">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"
android:fontFamily="sans-serif-thin"
android:text="17:35"
android:textSize="24sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="sans-serif-thin"
android:hint="#string/action_pick_time"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I thought this will be a common question, but I couldn't find any answers......
Is it possible to center-aligned a (variable length) textview based on a percentage of the screen width?
In my case, I have 2 textview and I want to achieve something like this:
Another example:
The first textview is center-aligend 30% of the screenwidth, width=wrap_content, while the second textview takes up the rest of the space. The first textview's size should NOT be fixed (see picture above)
I do not want to do that programatically, as it will be expensive on my program. If possible it's better be in an xml layout file :)
Right now I can only achieve a "left-aligned" textview using layout_weight of LinearLayout (by putting a 30% dummy on the left), but I want center-alignment.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="3" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="another textview"
android:textColor="#FFFF0000"/>
</LinearLayout>
</LinearLayout>
With almost an hour testing this "..." layout, I succeeded with this :
<?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="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="40"
android:background="#android:color/transparent">
<RelativeLayout
android:id="#+id/left_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="0dp"
android:gravity="center"
android:padding="0dp"
android:singleLine="true"
android:text="first textview"
android:textColor="#FFFF0000" >
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#0000FF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#00FF00"
android:gravity="center"
android:text="textview"
android:textColor="#FFF" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/left_layout"
android:background="#0000FF"
android:gravity="center"
android:text="textview"
android:textColor="#FFF" />
</RelativeLayout>
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="60"
android:background="#FFFF0000"
android:gravity="right"
android:singleLine="true"
android:text="another textview"
android:textColor="#FFF" />
</LinearLayout>
Outputs
Finally in your Java, according to the green textview width or content length, you can change the layout_weight for other textviews programmatically.
This should help you
Have a nice day.
// try this way hope this will help you...
<?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:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="0.15"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.85">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="first Textview"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="second textview demo text "/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
try this one
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Work perfect checked by me.
I'm trying to lay some text out on left and right that have a mirroring position as below.
What's happening here is that the last row in the right column ("Some more text") is the widest so it pushes the two rows above further to the right. For the sake of symmetry, the left column is pushed further to the left. The text values are supposed to be dynamic. Does anyone know how the layouts should be designed?
Here's my code (sadly, it doesn't even align to the right!):
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1">
<RelativeLayout android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1">
<RelativeLayout android:id="#+id/description_30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
<TextView android:id="#+id/title_30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30 DAYS"/>
<TextView android:id="#+id/num_ds_30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title_30"/>
<TextView android:id="#+id/num_bs_30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/num_ds_30"/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout android:id="#+id/description_today"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="#id/description_30">
<TextView android:id="#+id/title_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="TODAY"/>
<TextView android:id="#+id/num_ds_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_below="#id/title_today"/>
<TextView android:id="#+id/num_bs_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_below="#id/num_ds_today"/>
</RelativeLayout>
</LinearLayout>
You can achieve something like that by nesting LinearLayouts. The outer LinearLayout would have an orientation=horizontal, and the two inner LinearLayout an orientation of vertical with each having a layout_weight=1 and the second (right) LinearLayout would also have gravity="right".
The code would be something like this.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
... />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="right">
<TextView
... />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I think using a RelativeLayout and aligning the TextViews to the left/right is a good approach. Like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/Text1_Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/Text2_Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/Text1_Left" />
<TextView
android:id="#+id/Text3_Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/Text2_Left" />
<TextView
android:id="#+id/Text1_Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/Text1_Left"
android:gravity="right" />
<TextView
android:id="#+id/Text2_Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/Text1_Right"
android:layout_toRightOf="#id/Text2_Left"
android:gravity="right" />
<TextView
android:id="#+id/Text3_Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/Text2_Right"
android:layout_toRightOf="#id/Text1_Left"
android:gravity="right" />
</RelativeLayout>
I am having a list view and its list items are generated using Array List and it creates unecessary white space which occupies much space.
How do I remove it from the list items?
Here is my list view:
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp" android:layout_weight="1"
android:divider="#android:color/transparent"
android:dividerHeight="10.0sp"/>
And my list items:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/photo"
android:layout_width="140dip"
android:layout_height="140dip"
android:paddingRight="15dp"
android:paddingLeft="15dp"/>
<TextView android:id="#+id/name"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#000000"
android:paddingTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/photo"/>
<TextView android:id="#+id/itemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/name"
android:layout_toRightOf="#id/photo"/>
<TextView android:id="#+id/price"
android:textSize="19sp"
android:textStyle="bold"
android:textColor="#32cd32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/itemDescription"
android:layout_toRightOf="#id/photo"/>
</RelativeLayout>
Screenshot:
just remove android:dividerHeight="10.0sp" from xml or make it 1sp or smaller
this may also the problem:
android:layout_height="0dp" android:layout_weight="1"
why not giving height as "wrap_content" ? no need to android:layout_weight="1" i think
use height wrap-content for relativelayout in listitems.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</RelativeLayout>
Try this for your row, change image and color to yours ..(Use linear)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#123133" >
<ImageView
android:id="#+id/photo"
android:layout_width="140dip"
android:layout_height="140dip"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAASDKDJ"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/itemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAASDKDJ" />
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAASDKDJ"
android:textColor="#32cd32"
android:textSize="19sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
The property android:dividerHeight="10.0sp" is making all the extra space. Put something lower like 3sp or 5sp.
I have a linearLayout which is surrounded by a scrollView in order to make it for smaller screens scrollable. In the linear layout I have 3 childs which are also linearlayout.
This is working fine. But I also want to support larger screens. At the moment I get with a larger screen space left on the bottom of the screen. I want to have the buttons (navigation bar) be always at the bottom. for larger screens (height) I would like to add at the top of the screen an empty view which fills out the space that is more provided by the larger screen.
How can I achieve that? i tried a lot with weight attribute but didnt get it working.
Here the layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#8db9f6"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#8db9f6">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="test"
android:id="#+id/test"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<ImageButton
android:id="#+id/btnName"
android:scaleType="center"
android:layout_width="60dp"
android:layout_height="48dp"
android:src="#android:drawable/ic_menu_edit">
</ImageButton>
</LinearLayout>
<EditText
android:id="#+id/edittest"
android:editable="false"
android:hint="#string/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<TextView
android:text="#string/optionalText"
android:id="#+id/test1"
android:paddingLeft="10dp"
android:textSize="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="#+id/space"
android:layout_width="fill_parent"
android:layout_marginTop="4dp"
android:layout_height="3sp"
android:background="#333142">
</TextView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="TEST TESt"
android:id="#+id/test2"
android:paddingLeft="10dp"
android:layout_marginTop="5dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/progressbar"/>
<ImageButton
android:id="#+id/btnPicture"
android:scaleType="center"
android:layout_width="60dp"
android:layout_height="48dp"
android:src="#android:drawable/ic_menu_edit">
</ImageButton>
</LinearLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#ffffff"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="150dip">
<ImageView
android:id="#+id/test3"
android:layout_width="400dip"
android:layout_height="150dip"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="#drawable/test1"/>
<TextView
android:id="#+id/text"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8dp"
android:text="test test"/>
</FrameLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_marginTop="3dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/scaleMinus"
android:textSize="14dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="#string/zoomOut"/>
<Button
android:id="#+id/scalePlus"
android:textSize="14dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="#string/zoomIn"/>
</LinearLayout>
<TextView
android:id="#+id/balken"
android:layout_width="fill_parent"
android:layout_marginTop="4dp"
android:layout_height="3sp"
android:background="#333142">
</TextView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="test test"
android:id="#+id/test3"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<EditText
android:id="#+id/test4"
android:editable="false"
android:layout_width="100dp"
android:layout_height="wrap_content">
</EditText>
<TextView
android:text="test"
android:id="#+id/mtest4"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<ImageButton
android:id="#+id/test5"
android:scaleType="center"
android:layout_width="60dp"
android:layout_height="48dp"
android:src="#android:drawable/ic_menu_edit">
</ImageButton>
</LinearLayout>
<TextView
android:id="#+id/balken"
android:layout_width="fill_parent"
android:layout_marginTop="4dp"
android:layout_height="3sp"
android:background="#333142">
</TextView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#000000"
android:paddingTop="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/save"
android:textSize="18dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="#string/save"/>
<Button
android:id="#+id/cancel"
android:textSize="18dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="#string/abort"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Wrap the entire layout in a Relative Layout. Use a relative layout as your root element and set the Linear Layout containing your buttons to layout_alignParentBottom="true" and the ScrollView set to layout_alignParentTop="true".
The LinearLayout containing the buttons and the ScrollView should be direct children of the RelativeLayout.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout <-- containing the layout minus the buttons
android:id="#+id/SV"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<The Rest Of The Layout>
</LinearLayout>
<LinearLayout
android:id="#+id/LLButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Buttons>
</LinearLayout>
</ScrollView>
If you want the buttons to be always at the bottom of the screen alignParentBottom. If you want the buttons to always be at the bottom of the scrollview alignBelow="#id/SV"
android:layout_height="wrap_content" in your inner LinearLayout is your trouble here, changing it to 'fill_parent' should help. In general, you may want to use hierarchyviewer to help troubleshoot layout issues like this.