I want to allign the checkboxes in a list view to right most part of the screen.
my Layout is shown 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="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="vertical">
<TextView
android:id="#+id/nameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="30sp" />
<TextView
android:id="#+id/numberTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number"
android:textSize="25sp" />
</LinearLayout>
<CheckBox
android:id="#+id/checkBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_weight="2"
android:gravity="right|center" />
But When i run this i get the output as checkboxes right next to the textview
Found mistake.. its in mainactivity.. i have put the the width of listview as wrap content instead of fill parent
Use RelativeLayout for ChechBox Section and Add android:layout_alignParentRight="true" .Try this way ,Let me inform .
Okay,You can set 2 Textview and ChechBox on same row using layout weight (Linear Layout). And set gravity,layout gravity right for ChechBox.
<?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="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/nameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="30sp" />
<TextView
android:id="#+id/numberTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number"
android:textSize="25sp" />
</LinearLayout>
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Check this one
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/nameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="30sp" />
<TextView
android:id="#+id/numberTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number"
android:textSize="25sp" />
</LinearLayout>
<CheckBox
android:id="#+id/checkBox"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_marginRight="2dp"
android:gravity="right|center" />
</LinearLayout>
Related
In android application I use listview inside listview,
But the list view cut the data
the item is cut of
the other items I don't see at all
Here is the image shown that the single item is cut of, and the second item does not shown at all.
Any idea how can I change the height to be dynamic with the content
Thanks
First List View Item
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:padding="10dp">
<ImageView
android:id="#+id/approvedIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
app:srcCompat="#android:drawable/btn_star_big_on" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/travelLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
android:textSize="20sp"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="#+id/travelDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="#+id/countCompanies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/companiesListView"
/>
</LinearLayout>
</LinearLayout>
Second list view item
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal">
<TextView
android:id="#+id/cidTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="11sp"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="#+id/companyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="TextView" />
<TextView
android:id="#+id/comapnyAddedDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="TextView" />
<Button
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:text="Accept" />
</LinearLayout>
First use RecyclerView.
If you show the XML it will be helpful.
For the dynamic height use wrap_content for the text
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 have the Below Layout. I want the linear layout that holds the Textviews to appear below the PieChart. However it appears on top and on smaller screens the piechart overlays over the text.
<?xml version="1.0" encoding="utf-8"?>
<uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/catexprpt_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.echo.holographlibrary.PieGraph
android:id="#+id/piegraph"
android:paddingTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/tableRowN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:layout_below="#+id/piegraph"
android:orientation="horizontal" >
<TextView
android:id="#+id/titleN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_edges"
android:text="#string/note"
android:textColor="#ffffff"
android:textSize="13sp"
android:typeface="serif" />
<TextView
android:id="#+id/notice3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:typeface="serif" />
</LinearLayout>
Can you try with the PieGraph as a child of the LinearLayout.
I'm not sure about ActionBarSherlock's PullToRefreshLayout but the Android implementation SwipeRefreshLayout supports only one direct child view.
Edit:
I'm suggesting something like this as an only child to the Refresh layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.echo.holographlibrary.PieGraph
android:id="#+id/piegraph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip" />
<TextView
android:id="#+id/titleN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/piegraph"
android:background="#drawable/rounded_edges"
android:text="#string/note"
android:textColor="#ffffff"
android:textSize="13sp"
android:typeface="serif" />
<TextView
android:id="#+id/notice3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/piegraph"
android:textColor="#000000"
android:typeface="serif" />
</RelativeLayout>
More on layout optimization here.
I managed to solve it as below thanks to # LordRaydenMK :
<?xml version="1.0" encoding="utf-8"?>
<uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/catexprpt_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/tableRowM"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.echo.holographlibrary.PieGraph
android:id="#+id/piegraph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/tableRowN"
android:paddingBottom="20dp" />
<LinearLayout
android:id="#+id/tableRowN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<TextView
android:id="#+id/titleN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_edges"
android:text="#string/note"
android:textColor="#ffffff"
android:textSize="13sp"
android:typeface="serif" />
<TextView
android:id="#+id/notice3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Heloooooo Mr. Fish"
android:typeface="serif" />
</LinearLayout>
i've got a ListView with a custom adapter so i can customize the single row. I would create a view in the layout on the left that has as height all row height, and as width something like 5dp. So it will be like a little "strip" on the left of each row in the listview. I tried in this way
<?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="wrap_content"
android:layout_margin="5dp"
android:background="#layout/cardwhite"
android:orientation="vertical" >
<TextView
android:id="#+id/first"
android:layout_toRightOf="#+id/viewlist"
android:layout_marginLeft="5dp"
android:textSize="15dp"
android:fontFamily="sans-serif-light"
android:text="Partenza "
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:id="#id/viewlist"
android:gravity="left"
android:layout_width="5dp"
android:background="#52BD4F"
android:layout_margin="5dp"
android:layout_height="match_parent"
/>
<TextView
android:id="#+id/second"
android:layout_toRightOf="#id/viewlist"
android:layout_below="#id/first"
android:textSize="15dp"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
But using android:layout_height="match_parent" or android:layout_height="wrap_content" not works and the strip doesn't appear. If i write android:layout_height="20dp" it goes but of course it's not "dynamic". I don't understand why it desappears.. Any ideas?
Please modify the layout accordingly. I have already done this one, so I'm just pasting it. You just need to make use of android:layout_alignBottom and android:layout_alignTop with proper id inside your View. Here is the screen shot !
<?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:background="#e5e4e2" >
<RelativeLayout
android:id="#+id/relative_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/btn_normal" >
<TextView
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignBottom="#+id/tv_type"
android:layout_alignTop="#+id/tv_dayName"
android:background="#00ff00" />
<TextView
android:id="#+id/tv_dayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:layout_marginLeft="5dp"
android:text="Monday"
android:textColor="#000000"
android:textSize="14sp" >
</TextView>
<TextView
android:id="#+id/tv_dateNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:text="23"
android:textColor="#000000"
android:textSize="14sp" >
</TextView>
<TextView
android:id="#+id/tv_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_dayName"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:layout_marginLeft="5dp"
android:text="Mark Attendance"
android:textColor="#000000"
android:textSize="12sp" >
</TextView>
<TextView
android:id="#+id/tv_monthName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_dateNumber"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:text="Apr-14"
android:textColor="#000000"
android:textSize="12sp" >
</TextView>
</RelativeLayout>
<!--
<TextView android:id="#+id/tv_line"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#drawable/text_line"
android:layout_below="#+id/relative_row"/>
-->
</RelativeLayout>
<?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="wrap_content"
android:layout_margin="5dp"
android:background="#layout/cardwhite"
android:orientation="vertical" >
<TextView
android:id="#+id/first"
android:layout_toRightOf="#+id/viewlist"
android:layout_marginLeft="5dp"
android:textSize="15dp"
android:fontFamily="sans-serif-light"
android:text="Partenza "
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:id="#id/viewlist"
android:gravity="left"
android:layout_alignTop="#+id/first"
android:layout_alignBottom="#+id/second"
android:layout_width="5dp"
android:background="#52BD4F"
android:layout_margin="5dp"
android:layout_height="match_parent"
/>
<TextView
android:id="#+id/second"
android:layout_toRightOf="#id/viewlist"
android:layout_below="#id/first"
android:textSize="15dp"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Dont use relative layout just linearLayout
sample:
Beware that I dont have your cardwhite image so it wont be look like that one that you posted but just put the image in the linear layout background and it will look like the same as the one you posted.
<?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:layout_margin="5dp"
android:background="#layout/cardwhite"
android:orientation="horizontal" >
<View
android:id="#id/viewlist"
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#52BD4F" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:text="Customer 1"
android:textSize="15dp" />
<TextView
android:id="#+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:fontFamily="sans-serif-light"
android:text="Meeting"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
result:
Here is a small trick. Instead of giving height to the view use a TextView and give Height as MatchParant and set TextSize according to your need and set Background color to your TextView. Hope this helps you!
<TextView
android:id="#+id/col_status"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:background="#FFFFFF"
android:rotation="180"
android:textColor="#color/main_list_text"
android:textSize="12sp" />
I have this layout which is a row item of a ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:clickable="true"
android:gravity="center" >
<ToggleButton
android:id="#+id/taskActiveToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="ToggleButton" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/taskNameTextView"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/taskScheduleTextView"
android:layout_width="200dp"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/taskMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="..." /></LinearLayout>
I am having troubles adding another button to left of the (...) button.
I want to add the button so the row will keep its proportions (take all width of the line)
Any ideas?
As far as I can see, you are using horizontal LinearLayout as a root layout for your items. I would change it to RelativeLayout. Also if you need your layout occupy the whole width - you need to get rid of 200dip hardcoding and replace it with match_parent
Here is what I got using RelativeLayout:
<?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="wrap_content">
<ToggleButton
android:id="#+id/taskActiveToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"
android:text="ToggleButton" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/taskActiveToggleButton"
android:layout_toLeftOf="#+id/anotherButton"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="#+id/taskNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text" />
<TextView
android:id="#+id/taskScheduleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sub Text"/>
</LinearLayout>
<Button
android:id="#+id/anotherButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/taskMenuButton"
android:text="But2" />
<Button
android:id="#+id/taskMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:text="..." />
</RelativeLayout>