The build of my custom list row looks fine, but when I run the app the text fields on the right appear off the screen. API 23.
Here is the listview
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.archerdx.fusionlibrary.FusionList">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fusionListView">
</ListView>
</RelativeLay
out>
And here is the xml file of the custom rows I'm using
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3"
android:rowCount="4"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="384dp"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/fusionName"
android:layout_gravity="fill_horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_row="0"
android:layout_column="0"
android:layout_columnSpan="3"
android:textColor="#5987c6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Sources"
android:id="#+id/textView"
android:layout_row="1"
android:layout_column="0"
android:textSize="22dp"
android:layout_gravity="center|left"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:textColor="#000000" />
<TextView
android:layout_width="154dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/sourceName"
android:layout_weight="0.06"
android:layout_row="1"
android:layout_column="1"
android:layout_columnSpan="2"
android:gravity="right|center_vertical"
android:layout_marginRight="5dp"
android:textColor="#5987c6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Number of References"
android:id="#+id/textView2"
android:layout_row="2"
android:layout_column="0"
android:textSize="22dp"
android:layout_gravity="center|left"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:singleLine="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/numberOfReferences"
android:layout_gravity="fill_horizontal"
android:layout_row="2"
android:layout_column="1"
android:layout_columnSpan="2"
android:gravity="right|center_vertical"
android:textIsSelectable="true"
android:layout_marginRight="5dp"
android:textColor="#5987c6" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:id="#+id/button"
android:layout_weight="0.03"
android:layout_row="3"
android:layout_column="0"
android:layout_marginLeft="20dp" />
</GridLayout>
Give the width to your textviews wrap_content. Or if you want to show in single line the use this in your textviews:
android:ellipsize="end"
android:singleLine="true"
You're using fixed layout widths, weights and a gridview which is never going to be a flexible solution.
Look in to using Linear or Relative layouts instead. There's plenty of info out there.
Related
I was trying to make an app for an assignment in which I was using a table however the screen on the preview was larger than the screen of my phone so the table ended up to be too big I was told to use match parent to make the table auto adjust to the screen size on the phone however that did not work so i am seeking help.Screenshot of issue
Edit: I took the edit text and checkbox out of the table and that fixed the issue.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="TOY CARS" />
<TableLayout
android:id="#+id/table1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textview1"
android:stretchColumns="0,1,2,3,4">
<TableRow>
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="0"
android:text="Hot Wheels" />
<TextView
android:layout_column="1"
android:text="$50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="ADD" />
<Button
android:id="#+id/button2"
android:text="REMOVE"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="3"/>
<TextView
android:id="#+id/textview6"
android:text="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="4"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:text="Trandformers" />
<TextView
android:layout_column="1"
android:text="$100" />
<Button
android:id="#+id/button3"
android:text="ADD"/>
<Button
android:id="#+id/button4"
android:text="REMOVE"/>
<TextView
android:id="#+id/textview7"
android:text="0"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:text="Tonka" />
<TextView
android:layout_column="1"
android:text="$150" />
<Button
android:id="#+id/button5"
android:text="ADD"/>
<Button
android:id="#+id/button6"
android:text="REMOVE"/>
<TextView
android:id="#+id/textview8"
android:text="0"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:text="ZipZaps" />
<TextView
android:layout_column="1"
android:text="$200" />
<Button
android:id="#+id/button7"
android:text="ADD"/>
<Button
android:id="#+id/button8"
android:text="REMOVE"/>
<TextView
android:id="#+id/textview9"
android:text="0"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coupon Code: "
android:layout_column="0"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Coupon Code"
android:layout_toRightOf="#+id/textview10"/>
</TableRow>
<TableRow>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="VAT"/>
</TableRow>
</TableLayout>
<TextView
android:id="#+id/textview11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Area Code"
android:layout_below="#+id/table1"/>
<RadioGroup
android:id="#+id/radiogroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textview11">
<RadioButton
android:id="#+id/radiobutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="33100-34000"/>
<RadioButton
android:id="#+id/radiobutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="34000-35001"/>
<RadioButton
android:id="#+id/radiobutton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00000"/>
</RadioGroup>
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/radiogroup1"
android:text="Calculate"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$00000"
android:layout_below="#+id/radiogroup1"
android:layout_toRightOf="#+id/button9"
android:layout_marginLeft="20px"
android:textSize="25dp"/>
</RelativeLayout>
I would try adding the android:shrinkColumns attribute in the same way you added the android:stretchColumns attirbute. The stretchColumns attribute allows the table columns to stretch to fit a large parent, and the shrinkColumns attribute will allow them to shrink to fit a small parent. You can have both attributes on the layout at the same time, and they'll both work.
I have an android layout with some title bar and some input fields, and when I try to input some values, I can do it, but
the title bar vanishes
If I want to edit the field "Another number" I cannot scroll down to use the SeekBar instead.
How can I change the layout to make it
Have the title bar (with the text "InputExample") always fixes
Have the other content of the screen scrollable (so that I can use the SeekBar, for example)?
The layout is here:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:layout_marginBottom = "0dp">
<GridLayout
android:id="#+id/grid"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/new_cancel"
android:alignmentMode="alignBounds"
android:columnCount="10"
android:columnOrderPreserved="false"
android:useDefaultMargins="true">
<TextView
android:id="#+id/textTitleEdit"
android:layout_column="0"
android:layout_columnSpan="10"
android:layout_gravity="center_horizontal"
android:layout_row="0"
android:text="My Title"
android:textSize="32dip"/>
<TextView
android:text="You can enter some values"
android:textSize="16dip"
android:layout_columnSpan="8"
android:layout_gravity="left"
android:id="#+id/textSubTitleEdit"
android:layout_row="1"
android:layout_column="0" />
<TextView
android:text="Name"
android:layout_gravity="right"
android:layout_row="2"
android:layout_column="0"
/>
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_name"
android:layout_row="2"
android:layout_column="1" />
_____________
<TextView
android:text="Label"
android:layout_gravity="right"
android:layout_row="3"
android:layout_column="0" />
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_label"
android:layout_row="3"
android:layout_column="1" />
______
<TextView
android:layout_column="0"
android:text="Put in a number"
android:layout_gravity="right"
/>
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_price"
android:inputType="numberDecimal"
android:layout_row="4"
android:layout_column="1" />
<TextView
android:layout_column="0"
android:text="Another number"
android:layout_gravity="right"
android:layout_row="5" />
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_offset"
android:inputType="number"
android:layout_row="5"
android:layout_column="1" />
<SeekBar
android:id="#+id/seek_offset"
style="#android:style/Widget.Holo.SeekBar"
android:layout_width="150dp"
android:layout_column="1"
android:layout_row="6"
android:max="20"/>
<TextView
android:text="Comment"
android:layout_gravity="right"
android:layout_row="7"
android:layout_column="0" />
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_comment"
android:layout_row="7"
android:layout_column="1" />
</GridLayout>
<Button
android:id="#+id/new_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#aaaaaa"
android:text="Cancel"
android:layout_margin="5dp"
/>
<Button
android:id="#+id/new_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="#dddddd"
android:text="Ok"
android:layout_margin="5dp"
/>
</RelativeLayout>
</FrameLayout>
Was having some problems with your original layout so I've fixed it up and I think this solution should work. Everything in the preview of the layout has it positioned correctly so hopefully when you use this in the emulator it should work.
I personally prefer using LinearLayouts with weights for the majority of my layouts, I know some others prefer RelativeLayouts.
Essentially you should look to contain the part which you wish to scroll with a layout of some kind and then the ScrollView contains this layout so it can be scrolled. This is why I've removed the title and subtitle from the GridLayout.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:weightSum="6">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:orientation="vertical"
android:gravity="bottom|center_horizontal">
<TextView
android:id="#+id/textTitleEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="My Title"
android:textSize="32dip"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You can enter some values"
android:textSize="16dip"
android:layout_gravity="center_horizontal"
android:id="#+id/textSubTitleEdit"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<GridLayout
android:id="#+id/grid"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alignmentMode="alignBounds"
android:columnCount="10"
android:columnOrderPreserved="false"
android:useDefaultMargins="true">
<TextView
android:text="Name"
android:layout_gravity="right"
android:layout_row="2"
android:layout_column="0"/>
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_name"
android:layout_row="2"
android:layout_column="1"/>
<TextView
android:text="Label"
android:layout_gravity="right"
android:layout_row="3"
android:layout_column="0"/>
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_label"
android:layout_row="3"
android:layout_column="1" />
<TextView
android:layout_column="0"
android:text="Put in a number"
android:layout_gravity="right"
/>
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_price"
android:inputType="numberDecimal"
android:layout_row="4"
android:layout_column="1" />
<TextView
android:layout_column="0"
android:text="Another number"
android:layout_gravity="end"
android:layout_row="5" />
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_offset"
android:inputType="number"
android:layout_row="5"
android:layout_column="1" />
<SeekBar
android:id="#+id/seek_offset"
style="#android:style/Widget.Holo.SeekBar"
android:layout_width="150dp"
android:layout_column="1"
android:layout_row="6"
android:max="20"/>
<TextView
android:text="Comment"
android:layout_gravity="right"
android:layout_row="7"
android:layout_column="0" />
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_comment"
android:layout_row="7"
android:layout_column="1" />
</GridLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:gravity="bottom|center_horizontal"
android:weightSum="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:layout_weight="1">
<Button
android:id="#+id/new_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity=""
android:background="#aaaaaa"
android:text="Cancel"
android:layout_margin="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_weight="1">
<Button
android:id="#+id/new_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#dddddd"
android:text="Ok"
android:layout_margin="5dp"/>
</RelativeLayout>
</LinearLayout>
I am new at developing Android app.I have 4 EditText corresponding 4 TextView.but I have a problem with EditTexts,they dont fit properly.How can I handle this problem.Following is my xml layout file.Please help me,what is wrong.Thank you in advance.
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.mobilecoursemanagementsystem.AddCourseActivity"
android:orientation="vertical">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="5"
android:columnCount="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Course Title"
android:layout_column="0"
android:layout_row="0"
android:id="#+id/txtTitle"/>
<!--android:layout_marginTop="10dp"-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:layout_marginTop="10dp"
android:id="#+id/editTitle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:layout_marginTop="10dp"
android:text="Course Code"
android:id="#+id/txtCode"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:layout_marginTop="10dp"
android:id="#+id/editCode" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="2"
android:layout_marginTop="10dp"
android:text="Number of Student"
android:id="#+id/txtNumberOfSts"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_marginTop="10dp"
android:id="#+id/editNumberOfSts" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="3"
android:layout_marginTop="10dp"
android:text="Course Level"
android:id="#+id/txtLevel"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:layout_marginTop="10dp"
android:id="#+id/editLevel" />
</GridLayout>
</LinearLayout>
click for Screenshoot
user layout_margins in your layout for every edittext
android:layout_marginRight="10dp"
set whatever value you like for margin
I have a ListView in my Activity.
Each ListView item use (in a array adapter) this layout:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="#ffffff"
android:columnCount="2"
android:rowCount="1" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_margin="5dp"
android:layout_row="0"
android:rowCount="3" >
<TextView
android:id="#+id/settingsHeader"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="0"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/settingsContent"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="2"
android:layout_width="match_parent"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</GridLayout>
<Switch
android:id="#+id/settingsToggle"
android:layout_column="1"
android:layout_marginRight="5dp"
android:layout_gravity="center_vertical|right"
android:layout_row="0"/>
</GridLayout>
But my problem is, that the layout is beyond the right margin. I think it's because the TextView settingsContent is not wrap the text. How can i solve this problem?
Add these piece of code to your TextView settingsContent.
android:ellipsize="end"
android:ems="9"
android:lines="1"
android:singleLine="true"
Set the width of your 1st GridLayout to 'fill_parent'.
XML will be like this:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="#ffffff"
android:columnCount="2"
android:rowCount="1" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_margin="5dp"
android:layout_row="0"
android:rowCount="3" >
<TextView
android:id="#+id/settingsHeader"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="0"
android:ellipsize="end"
android:ems="9"
android:lines="1"
android:singleLine="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/settingsContent"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="2"
android:layout_width="match_parent"
android:ellipsize="end"
android:ems="9"
android:lines="1"
android:singleLine="true"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</GridLayout>
<Switch
android:id="#+id/settingsToggle"
android:layout_column="1"
android:layout_marginRight="5dp"
android:layout_gravity="center_vertical|right"
android:layout_row="0"/>
This will might help you.
Try this..
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:background="#ffffff"
android:columnCount="2"
android:rowCount="1" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_margin="5dp"
android:layout_row="0"
android:rowCount="3" >
<TextView
android:id="#+id/settingsHeader"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="0"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/settingsContent"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="2"
android:layout_width="match_parent"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</GridLayout>
<Switch
android:id="#+id/settingsToggle"
android:layout_column="1"
android:layout_marginRight="5dp"
android:layout_gravity="center_vertical|right"
android:layout_row="0"/>
You might try the following code which will give you the same look..
<?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="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:gravity="center"
android:orientation="vertical"
android:layout_margin="2dp">
<TextView
android:id="#+id/settingsHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textStyle="bold"
android:textColor="#696969"
android:layout_gravity="center"
android:text="hello how are you guys"/>
<TextView
android:id="#+id/settingsContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textColor="#9C9A9A"
android:layout_gravity="center"
android:text="I am fine wat abt u"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center|right"
android:orientation="vertical"
android:layout_margin="5dp">
<Switch
android:id="#+id/settingsToggle"
android:layout_width="60dp"
android:layout_height="25dp"
android:layout_margin="3dp"
android:textColor="#FFFFFF"
android:gravity="center"
android:text="Error"
android:background="#942B2A"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have a simple ListView:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/overvieList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and this layout for the ListView items:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="2" >
<ImageView
android:id="#+id/overviewItemImage"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_marginRight="5dp"
android:layout_row="0"
android:src="#drawable/ic_launcher" />
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="left|top"
android:layout_row="0"
android:layout_marginLeft="3dp"
android:layout_marginRight="5dp"
android:columnCount="1"
android:rowCount="3" >
<TextView
android:id="#+id/overviewItemHeader"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="0"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/overviewItemCategory"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="10sp"
android:textStyle="italic" />
<TextView
android:id="#+id/overviewItemText"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="2"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</GridLayout>
</GridLayout>
</LinearLayout>
Now i use a modified ArrayAdapter to fill the ListView.
ok that works.
But how can I prevent it that the TextViews Content (on the right) goes over the edge??
set layout_marginRight in textview . i hope this will solve your problem
just add a little margin android:layout_marginRight="5dp" to your TextViews