When creating a listview layout, is it advisable to keep the layouts as simple as possible with relative layouts and minimal images and text, or is it ok to make them a little fancier with a couple of buttons, possibly an image or two, and some text within tablelayouts?
I am trying to minimise the clicks/touches to get to the pertinent information, and giving the user a nicer UI to play with as opposed to a bog standard list.
I've tried to research it but cant find guidlines on design layout and limitations on listviews.
Something tells me the xml below is the cause of the choking the listview experiences if the resultset grows to more than say 20?
Thank you.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#color/White" android:gravity="center">
<TableLayout android:layout_height="wrap_content" android:id="#+id/tableLayout1" android:layout_width="fill_parent">
<TableRow android:id="#+id/tableRow1" android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/linearLayout2">
<ImageView android:layout_marginRight="10px" android:layout_width="60dip" android:layout_marginTop="4px" android:id="#+id/icon" android:layout_height="60dip" android:src="#drawable/indian" android:layout_marginLeft="4px"></ImageView>
<TableLayout android:layout_height="match_parent" android:id="#+id/tableLayout2" android:layout_width="fill_parent">
<TableRow android:id="#+id/tableRow5" android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:focusableInTouchMode="false" android:paddingTop="5dip" android:textColor="#color/Black" android:id="#+id/title" android:textSize="18dip" android:layout_height="wrap_content" android:maxLines="10" android:layout_gravity="left" android:focusable="false" android:layout_width="fill_parent" android:text="#+id/label"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow6" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:textColor="#color/Black" android:layout_height="wrap_content" android:id="#+id/distanceText" android:textSize="12dip" android:layout_width="wrap_content" android:gravity="center" android:layout_gravity="left" android:text="TextView"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
</TableRow>
<TableRow android:id="#+id/tableRow2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:paddingBottom="15dip">
<LinearLayout android:id="#+id/linearLayout3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableLayout android:layout_height="match_parent" android:id="#+id/tableLayout3" android:layout_width="fill_parent">
<TableRow android:layout_height="match_parent" android:id="#+id/tableRow8" android:layout_width="fill_parent">
<ImageView android:id="#+id/introImage" android:layout_height="wrap_content" android:layout_width="fill_parent" android:scaleType="fitStart" android:paddingLeft="8dip"></ImageView>
</TableRow>
<TableRow android:id="#+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:linksClickable="true" android:textColor="#color/Black" android:layout_height="wrap_content" android:focusable="false" android:text="more" android:autoLink="all" android:textColorLink="#color/Aqua" android:textSize="12dip" android:clickable="true" android:paddingRight="5dip" android:id="#+id/intro" android:paddingTop="5dip" android:focusableInTouchMode="false" android:paddingLeft="5dip" android:layout_width="wrap_content"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow7" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/description" android:text="description" android:visibility="invisible" android:paddingLeft="5dip" android:paddingRight="5dip" android:textColor="#color/Black" android:textSize="12dip" android:autoLink="all" android:clickable="true" android:linksClickable="true" android:textColorLink="#color/DarkGray"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
</TableRow>
<TableRow android:id="#+id/tableRow3" android:layout_height="wrap_content" android:layout_width="fill_parent" android:background="#drawable/listviewmenu" android:layout_gravity="center_horizontal" android:gravity="center_horizontal">
<LinearLayout android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_gravity="center" android:gravity="center">
<Button android:id="#+id/mapClick" android:layout_height="wrap_content" android:text="#string/map_info" android:layout_width="wrap_content" android:background="#drawable/actionbutton" android:textColor="#color/White" android:textColorHighlight="#color/AntiqueWhite" android:textStyle="bold" android:gravity="center"></Button>
<Button android:id="#+id/moreClick" android:layout_height="wrap_content" android:text="#string/more_info" android:layout_width="wrap_content" android:textColor="#color/White" android:textColorHighlight="#color/Aqua" android:textStyle="bold" android:gravity="center" android:background="#drawable/actionmore"></Button>
</LinearLayout>
</TableRow>
</TableLayout>
The following is the same layout but use only one RelativeLayout:
<?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"
android:background="#android:color/white" >
<ImageView
android:id="#+id/icon"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:layout_marginTop="4px"
android:src="#android:drawable/dialog_frame" >
</ImageView>
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/icon"
android:focusable="false"
android:focusableInTouchMode="false"
android:maxLines="10"
android:paddingTop="5dip"
android:text="#+id/label"
android:textColor="#android:color/black"
android:textSize="18dip" >
</TextView>
<TextView
android:id="#+id/distanceText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_gravity="left"
android:layout_toRightOf="#+id/icon"
android:gravity="center"
android:text="TextView"
android:textColor="#android:color/black"
android:textSize="12dip" >
</TextView>
<ImageView
android:id="#+id/introImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/icon"
android:paddingLeft="8dip"
android:scaleType="fitStart" >
</ImageView>
<TextView
android:id="#+id/intro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/introImage"
android:autoLink="all"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:linksClickable="true"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="5dip"
android:text="more"
android:textColor="#android:color/black"
android:textColorLink="#android:color/primary_text_light"
android:textSize="12dip" >
</TextView>
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/intro"
android:autoLink="all"
android:clickable="true"
android:linksClickable="true"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:text="description"
android:textColor="#android:color/black"
android:textColorLink="#android:color/darker_gray"
android:textSize="12dip"
android:visibility="invisible" >
</TextView>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="#android:drawable/dialog_frame" >
<Button
android:id="#+id/mapClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/dialog_frame"
android:text="map_info"
android:textColor="#android:color/white"
android:textColorHighlight="#android:color/secondary_text_light"
android:textStyle="bold" >
</Button>
<Button
android:id="#+id/moreClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/dialog_frame"
android:gravity="center"
android:text="more_info"
android:textColor="#android:color/white"
android:textColorHighlight="#android:color/primary_text_light"
android:textStyle="bold" >
</Button>
</LinearLayout>
</RelativeLayout>
I just changed color, string and drawable references to see if it works!
RelativeLayout rulez!
It is suggested to keep the layouts of the ListView items simple - and by that I mean fast performing. Simple does not mean boring :)
RelativeLayouts are best for rows of a ListView since they require only one pass to render, as opposed to say, nested LinearLayouts (as mentioned here). However, if you must go beyond the simple and include a bit of fancy stuff in your rows, there are a couple of tricks provided by the platform to help you.
Use the convertView optimization - i.e, in the getView() method of your Adapter, check to see if the convertView parameter is null. If it isn't then just use that object, and modify it with new values instead of inflating a new one.
Even if you use option 1 above, use the ViewHolder pattern to not only avoid inflation; but also optimize the "modifying the row with new values" step. This is described in this talk.
Related
I am trying to do my first complex GUI, but now i can't to solve this problem.
The first column of the first two rows only needs to contain the label, while the second column of the first two rows must occupy the remaining space.
In this snapshot the problem that i noticed is that the first column is larger than i would like.
This is the piece of code that implements that piece of layout.
...
...
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/linear_layout_background"
android:stretchColumns="*"
android:shrinkColumns="*">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp" >
<TextView
android:id="#+id/textViewPlateValueLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/plateValue"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/productID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:ems="5"
android:text="#string/blank"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp" >
<TextView
android:id="#+id/ztlLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ztl"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/ztlShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:text="#string/blank"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="#+id/isAllowed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/blank"
android:background="#drawable/back"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
...
...
In addition, since they are really impractical, I would like to ask you some advice on the best approaches to use than this.
You can try using layout_weight like this:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context=".MainActivity" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#ff00ff"
android:stretchColumns="*"
android:shrinkColumns="*">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<TextView
android:id="#+id/textViewPlateValueLabel"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Label1:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/productID"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00ff00"
android:ems="5"
android:text="Some Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<TextView
android:layout_weight="3"
android:id="#+id/ztlLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Label2:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_weight="7"
android:id="#+id/ztlShow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00ff00"
android:text="Some Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="#+id/isAllowed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"
android:background="#0088ff"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
</LinearLayout>
I wouldn't use TableLayout, if I were you. I'd probably use LinearLayout or RelativeLayout. You can get the same effect with some of the XML attributes. This is akin to using HTML's table attribute vs. using divs to simulate tables.
So, instead of a table, you can have LinearLayout inside of LinearLayout to simulate a table.
Although canDroid, could be sufficient to some of us, it didn't worked for me, I tried all kind of tricks to make the TableLayout to work. I found LinearLayout much easier to use, here is an example of TableLayout "like" layout using LinearLayout, few cells with a thumbnail, and few without.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="94dp"
android:layout_margin="5dp"
android:text="#string/nut1" />
</LinearLayout>
<View
android:layout_width="395dp"
android:layout_height="2dp"
android:background="#color/colorPrimary"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="0dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<ImageView
android:layout_width="94dp"
android:layout_height="94dp"
android:adjustViewBounds="false"
android:background="#drawable/one"
android:contentDescription="#string/nut3"
android:cropToPadding="false"
android:saveEnabled="false"
android:scaleType="center" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="94dp"
android:layout_margin="10dp"
android:text="#string/nut3" />
</LinearLayout>
</LinearLayout>
I am designing a login page which has EditText and TextView for username & password and buttons for sign-in & reset. I need to place my buttons in a single column so that the first column should be empty and second column should have 2 buttons. Can anyone help me.
Thanks in advance.
This is my xml code.
<TableLayout
android:id="#+id/con1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25pt"
android:layout_marginRight="25pt"
android:gravity="center"
android:orientation="vertical" >
<TableRow android:layout_width="match_parent" android:gravity="center">
<TextView
android:id="#+id/lbl_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="76px"
android:layout_y="24px"
android:text="SignIn Here"
android:gravity="center"
>
</TextView>
</TableRow>
<TableRow android:layout_width="fill_parent">
<TextView
android:id="#+id/lbl_username"
android:layout_width="20pt"
android:layout_height="wrap_content"
android:layout_x="19px"
android:layout_y="57px"
android:gravity="left"
android:text="Username"
android:layout_weight="0.5">
</TextView>
<EditText
android:id="#+id/txt_username"
android:layout_width="20pt"
android:layout_height="wrap_content"
android:layout_x="54px"
android:layout_y="80px"
android:textSize="18sp"
android:layout_weight="0.5">
</EditText>
</TableRow>
<TableRow>
<TextView
android:id="#+id/lbl_password"
android:layout_width="20pt"
android:layout_height="wrap_content"
android:layout_x="21px"
android:layout_y="131px"
android:text="Password"
android:layout_weight="0.5">
</TextView>
<EditText
android:id="#+id/txt_password"
android:layout_width="20pt"
android:layout_height="47px"
android:layout_x="53px"
android:layout_y="155px"
android:password="true"
android:textSize="18sp"
android:layout_weight="0.5">
</EditText>
</TableRow>
<TableRow>
<LinearLayout >
<Button
android:id="#+id/btn_signin"
android:layout_width="80pt"
android:layout_height="wrap_content"
android:layout_x="52px"
android:layout_y="200px"
android:text="SignIn"
android:layout_weight="0.025">
</Button>
<Button
android:id="#+id/btn_reset"
android:layout_width="80pt"
android:layout_height="wrap_content"
android:layout_x="123dp"
android:layout_y="201px"
android:text="Reset"
android:layout_weight="0.025">
</Button>
</LinearLayout>
</TableRow>
</TableLayout>
If you want to follow this shady logic, i suggest using
<Space/>
or
<android.support.v4.widget.Space>
The docs say
Space is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.
You can set column number with android:layout_column argument
<TableRow>
<TextView
android:layout_column="1"
android:text="Save As..."
android:padding="3dip" />
<TextView
android:text="Ctrl-Shift-S"
android:gravity="right"
android:padding="3dip" />
</TableRow>
try this:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/con1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25pt"
android:layout_marginRight="25pt"
android:gravity="center"
android:orientation="vertical" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="#+id/lbl_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="76px"
android:layout_y="24px"
android:text="SignIn Here"
android:gravity="center"
>
</TextView>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/lbl_username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_x="19px"
android:layout_y="57px"
android:gravity="left"
android:text="Username" >
</TextView>
<EditText
android:id="#+id/txt_username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_x="54px"
android:layout_y="80px"
android:textSize="18sp" >
</EditText>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/lbl_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_x="21px"
android:layout_y="131px"
android:text="Password" >
</TextView>
<EditText
android:id="#+id/txt_password"
android:layout_width="0dp"
android:layout_height="47px"
android:layout_weight="1"
android:layout_x="53px"
android:layout_y="155px"
android:password="true"
android:textSize="18sp" >
</EditText>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/btn_signin"
android:layout_width="80pt"
android:layout_height="wrap_content"
android:layout_x="52px"
android:layout_y="200px"
android:text="SignIn"
android:layout_weight="0.025">
</Button>
<Button
android:id="#+id/btn_reset"
android:layout_width="80pt"
android:layout_height="wrap_content"
android:layout_x="123dp"
android:layout_y="201px"
android:text="Reset"
android:layout_weight="0.025">
</Button>
</LinearLayout>
</TableRow>
</TableLayout>
Output:
I have an xml layout that compiles fine but when I used the intent to change to the new view it force closes. I'm almost positive it has to do with my use of table and relative layouts. It's kind of a frankenstien monster of coding, haha. Please let me know if how I can remedy this force close problem. Also, before I had strickly table layout. With this layout it compiled and was fully functional, just not as a pretty. So the java should be fine (theoretically).
CODE:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="#+id/tableLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:background="#FFFFF0">
<RelativeLayout android:orientation="vertical" android:background="#drawable/banner"
android:layout_width="fill_parent" android:layout_height="50sp" android:gravity="center" >
</RelativeLayout>
<RelativeLayout android:id="#+id/tableTitle" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="#999">
<TextView android:id="#+id/ListingsTitle" android:text="Title: "
android:textColor="#000" android:textStyle="bold" android:textSize="20sp" />
<TextView android:id="#+id/sellingprice" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#000fff"
android:text="Price:" android:layout_below="#id/ListingsTitle" ></TextView>
<TextView android:id="#+id/mileage" android:layout_below="#id/ListingsTitle" android:layout_toRightOf="#id/sellingprice" android:layout_height="wrap_content" android:text="Mileage:" android:textColor="#000fff" android:layout_width="wrap_content"></TextView>
</RelativeLayout>
<RelativeLayout android:orientation="vertical" android:background="#FFFFF0"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="#+id/PhotoGallerybtn"
android:src="#drawable/icon" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"></ImageButton>
<Button android:text="Email the Dealer" android:id="#+id/EmailDealerbtn" android:layout_alignParentLeft="true"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="#id/PhotoGallerybtn"></Button>
<Button android:text="Add to Favs" android:id="#+id/Favsbtn" android:layout_below="#id/PhotoGallerybtn"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="#id/EmailDealerbtn"></Button>
<Button android:text="Share" android:id="#+id/Sharebtn" android:mimeType="image/*"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="#id/PhotoGallerybtn" android:layout_toRightOf="#id/Favsbtn"></Button>
</RelativeLayout>
<TableRow android:id="#+id/tableRow4" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#999">
<TextView android:id="#+id/textName" android:text="Details:"
android:textColor="#000" android:textStyle="bold" android:textSize="20sp" />
</TableRow>
<TextView android:id="#+id/bodystyle" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="#000"
android:text="Body Style:"></TextView>
<TextView android:id="#+id/color" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="#000"
android:text="Color:"></TextView>
<TextView android:id="#+id/doors" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="#000"
android:text="Doors:"></TextView>
<TextView android:id="#+id/engine" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="#000"
android:text="Engine:"></TextView>
<TextView android:id="#+id/vin" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textColor="#000"
android:text="VIN:"></TextView>
</TableLayout>
You should add layout_width and layout_height fields to your TextView with #+id/ListingsTitle id:
<TextView android:id="#+id/ListingsTitle" android:text="Title: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textStyle="bold"
android:textSize="20sp" />
i have a textview and a Menu , the textview is currently showing at the bottom of the screen and when menu pressed ,currently the menu hide the textview ,but i want the textview automatically move upwords so that everybody can see
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:background="#drawable/android_bg"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/navigationbar">
<TextView android:layout_width="wrap_content" android:layout_centerInParent="true"
android:id="#+id/banner_text"
android:layout_height="wrap_content" android:background="#drawable/bannertext_angies_list">></TextView>
<Button
android:layout_width="55dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_height="35dp"
android:background="#drawable/sign_out_button_clicked_button"
android:id="#+id/signout"/>
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<TextView
android:visibility="gone"
android:textColor="#000000"
android:text="Thank you, your report has been"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="260dp"
android:layout_height="fill_parent"
android:id="#+id/Thanks_to_submission1"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:visibility="gone"
android:paddingLeft="70dp"
android:textColor="#000000"
android:text="submitted successfuly!"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="260dp"
android:layout_height="fill_parent"
android:id="#+id/Thanks_to_submission2"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp">
<Button
android:layout_width="260dp"
android:layout_height="fill_parent"
android:background="#drawable/submitbutton"
android:id="#+id/submitreport_providertype_button"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<Button
android:layout_width="260dp"
android:layout_height="fill_parent"
android:background="#drawable/searchlist_button"
android:id="#+id/search_list_button"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<Button
android:layout_width="260dp"
android:layout_height="fill_parent"
android:background="#drawable/bigdeal_button"
android:id="#+id/big_deal_button"/>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="14sp"
android:textStyle="bold"
android:onClick="true"
android:textColor="#000000"
android:text="Or visit our website at" />
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="#+id/link"
android:gravity="center_vertical"
android:autoLink="web"
android:linksClickable="true"
android:layout_gravity="center"
android:textSize="14sp"
android:textStyle="bold"
android:onClick="true"
android:textColor="#000000"
android:text="#string/link" />
</LinearLayout>
<TextView
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="Or visit our website at" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
That's not really supported by Android, and it's by design. The idea is that you can use the full screen for your UI, and the menu takes up part of the space when you need to select it. You don't want to worry about text views and other things while the menu is up. This is better than the iPhone, where you permanently have to give up screen space for menu items. If something is really important, then move it away from the bottom of the screen.
If you're really bent on moving stuff around, you could intercept Activity.onPrepareOptionsMenu and move things around in your UI, although the function wasn't really meant for that purpose. Then matching call is onOptionsMenuClosed.
I'm having some trouble getting pictures inside a tablelayout...actually, each I have 2 columns and when i put a picture in a cell of the table, it's completely stretched and disproportionnated...I can't find how to make it stay it's original inside the cell and let the rest of the space filled by white background for instance....
XML is like that:
<TableLayout android:layout_width="fill_parent" android:stretchColumns="*"
android:layout_marginLeft="3dip" android:layout_marginRight="10dip"
android:layout_height="wrap_content">
<TableRow android:layout_marginBottom="10dip">
<TextView android:id="#+id/tv01" android:text="text1"
android:textSize="14sp" android:layout_margin="1dip"
android:layout_height="wrap_content" android:textColor="#color/bleuLink"
android:layout_width="wrap_content" android:layout_weight="1"
android:background="#color/background"></TextView>
<Button android:id="#+id/add" android:background="#drawable/addressbook"
android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
<Button android:id="#+id/call" android:background="#drawable/greenphone"
android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
Your images are stretching because of this line of code.
<TableLayout android:layout_width="fill_parent" android:stretchColumns="*" />
Because you tell your table to fill its parent and then set stretchable columns to all, your layout forces its children to fill the required space. Remove the stretchable columns attribute or set it to a comma delineated list of indexes for the columns you want to stretch.
<TableLayout android:layout_width="fill_parent"
android:stretchColumns="0, 2" android:layout_marginLeft="3dip"
android:layout_marginRight="10dip" android:layout_height="wrap_content">
<TableRow android:layout_marginBottom="10dip">
<TextView android:id="#+id/tv01" android:text="text1"
android:textSize="14sp" android:layout_margin="1dip"
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"></TextView>
<Button android:id="#+id/add" android:background="#drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
<Button android:id="#+id/call" android:background="#drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
</TableRow>
</TableLayout>
Try the code above as an example.
An alternative solution is to add the Button into a Layout and set the layout attribute android:layout_height="wrap_content".
<TableLayout android:layout_width="fill_parent"
android:stretchColumns="*" android:layout_height="wrap_content">
<TableRow>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center">
<TextView android:id="#+id/tv01" android:text="text1"
android:textSize="14sp" android:layout_margin="1dip"
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1">
</TextView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center">
<Button android:id="#+id/add" android:background="#drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center">
<Button android:id="#+id/call" android:background="#drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</Button>
</LinearLayout>
</TableRow>
</TableLayout>