Fixed horizontal ScrollView above ListFragment - android

I am displaying a list using a custom ListFragment. The fragment inflates a layout and works fine. I want to add a horizontal scrollView above the fragment to act as a category menu. It must be fixed, so addHeaderView is not acceptable.
I found a layout example here on SO and plugged it into my layout to see how it could be made to work. But in its current form below, it does what you would expect - puts a horizontal scrollview in every entry on the list.
So how do I share a screen with a static view on top and the listfragment below.
Here is the layout that does not work - as I mentioned the Scrollview part is not mine and is only included as an example. The relativelayout at the bottom makes the actual list
<?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:clickable="false" >
<HorizontalScrollView
android:id="#+id/hor_svID"
android:layout_width="wrap_content"
android:layout_height="35dip"
android:scrollbars="none"
android:fillViewport="false"
android:focusable="false" >
<!--android:background="#drawable/submenu_bg"> -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:focusable="false"
android:background="#FFFFFF"
android:gravity="center">
<TextView android:id="#+id/TechnologyTxtVId"
android:text="TECHNOLOGY"
android:textColor="#342D7E"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView android:id="#+id/SportsTxtVId"
android:text="SPORTS"
android:textColor="#342D7E"
android:textStyle="bold"
android:textSize="12sp"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="15dip"></TextView>
<TextView android:id="#+id/EntntTxtVId"
android:text="ENTERTAINMENT"
android:textStyle="bold"
android:paddingLeft="15dip"
android:textSize="12sp"
android:gravity="center"
android:textColor="#342D7E"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView android:id="#+id/LocalTxtVId"
android:text="LOCAL"
android:textStyle="bold"
android:paddingLeft="15dip"
android:textSize="12sp"
android:textColor="#342D7E"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView android:id="#+id/WorldTxtVId"
android:text="WORLD"
android:textStyle="bold"
android:textSize="12sp"
android:paddingLeft="15dip"
android:gravity="center"
android:textColor="#342D7E"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView android:id="#+id/FeaturesTxtVId"
android:text="FEATURES"
android:textStyle="bold"
android:textSize="12sp"
android:paddingLeft="15dip"
android:gravity="center"
android:textColor="#342D7E"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView android:id="#+id/RecentTxtVId"
android:text="RECENT"
android:textStyle="bold"
android:textSize="12sp"
android:paddingLeft="15dip"
android:gravity="center"
android:textColor="#342D7E"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false" >
<ImageView
android:id="#+id/imageView_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="#dimen/default_padding"
android:contentDescription="#null"
android:focusable="false"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageView_thumbnail"
android:layout_alignParentTop="true"
android:layout_marginRight="#dimen/default_padding"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView_pubDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="#dimen/default_padding"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<TextView
android:id="#+id/textViewHeadline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageView_thumbnail"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView_pubDate"
android:layout_marginLeft="#dimen/default_padding"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewHeadline"
android:layout_toRightOf="#+id/imageView_thumbnail"
android:maxLines="#integer/Four"
android:layout_marginLeft="#dimen/default_padding"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</RelativeLayout>

Related

How do you put two TextViews next to each other in a LinearLayout?

I am a beginner in Android Studios, and my TextViews will not be placed next to each other, instead one is on top of the other. I am really confused about what I did wrong.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="#string/already_registered"/>
<TextView
android:id="#+id/textview_login"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textColor="#ECAB71"
android:textSize="16sp"
android:text="#string/login"/>
</LinearLayout>
LinearLayout tag closed too early. Use > instead of /> in your LinearLayout element.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Already registered"/>
<TextView
android:id="#+id/textview_login"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textColor="#ECAB71"
android:textSize="16sp"
android:text="login"/>
</LinearLayout>
You must clear the backslash in line 5
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="#string/already_registered"/>
<TextView
android:id="#+id/textview_login"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textColor="#ECAB71"
android:textSize="16sp"
android:text="#string/login"/>
</LinearLayout>

Properly align images and text in relative layout?

I've a shop layout in which are three different sized images. To the right of them, there is text representing price. How can I align images and text under each other ? And put the middle of the screen between Image and text. Here is my layout:
<?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="#drawable/podklad">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lives"
android:focusable="false" android:background="#drawable/heart_image"
android:layout_below="#+id/money" android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price1"
android:textSize="30sp" android:textColor="#ff000000"
android:layout_alignTop="#+id/lives" android:layout_toRightOf="#+id/lives"
android:layout_toEndOf="#+id/lives"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/money" android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" android:textSize="40dp" android:textColor="#ff000000"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/monstertoprightcolored"
android:id="#+id/hardmode"
android:layout_centerVertical="true" android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price2"
android:textSize="30dp"
android:textColor="#ff000000"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/hardmode"
android:layout_toEndOf="#+id/hardmode"
android:layout_above="#+id/price3"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/monsterbottomleftcolored"
android:id="#+id/reversedmode"
android:layout_alignParentBottom="true" android:layout_alignLeft="#+id/hardmode"
android:layout_alignStart="#+id/hardmode"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price3"
android:textSize="30dp"
android:textColor="#ff000000"
android:layout_marginTop="26dp"
android:layout_below="#+id/hardmode"
android:layout_toRightOf="#+id/price2"
android:layout_toEndOf="#+id/price2"/>
A TableLayout might work better in this case. Here's a start to what your layout would look like:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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:stretchColumns="*">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:layout_gravity="right"
android:id="#+id/money"
android:textSize="40dp"
android:textColor="#ff000000"
tools:text="money" />
</TableRow>
<TableRow>
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/lives"
android:focusable="false"
android:background="#drawable/heart_image"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price1"
android:textSize="30sp"
android:textColor="#ff000000"
tools:text="price1" />
</TableRow>
<TableRow>
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/monstertoprightcolored"
android:id="#+id/hardmode" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price2"
android:textSize="30dp"
android:textColor="#ff000000"
tools:text="price2" />
</TableRow>
<TableRow>
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/monsterbottomleftcolored"
android:id="#+id/reversedmode" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price3"
android:textSize="30dp"
android:textColor="#ff000000"
android:layout_marginTop="26dp"
tools:text="price3" />
</TableRow>
</TableLayout>
Note that in order to "put the middle of the screen between Image and text", the two columns have to be equal in width. This is done by setting android:stretchColumns="*" in the TableLayout, and setting android:layout_width="0dp" and android:layout_weight="1" in the children of the TableRows.
See tablelayout - Set equal width of columns in table layout in Android for more info.
You can use linear layouts for this. Image and text can be split vertically in a linear layout. Each of this linear layout can be placed horizontally. Can you add a screenshot of how your layout should look for better understanding.
Here try this ,hope to help you, and i hope that i understand your problem correctly.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:background="#drawable/ic_launcher">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lives"
android:focusable="false"
android:background="#drawable/ic_launcher"
android:layout_below="#+id/money"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price1"
android:textSize="30sp"
android:text="Text"
android:textColor="#ff000000"
android:layout_alignTop="#+id/lives"
android:layout_toRightOf="#+id/lives"
android:layout_toEndOf="#+id/lives" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/money"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="40dp"
android:text="Text"
android:textColor="#ff000000" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:id="#+id/hardmode"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price2"
android:textSize="30dp"
android:textColor="#ff000000"
android:text="Text"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/hardmode"
android:layout_toEndOf="#+id/hardmode"
android:layout_above="#+id/price3" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:id="#+id/reversedmode"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/hardmode"
android:layout_alignStart="#+id/hardmode" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/price3"
android:textSize="30dp"
android:textColor="#ff000000"
android:layout_marginTop="26dp"
android:layout_below="#+id/hardmode"
android:text="Text"
android:layout_toRightOf="#+id/price2"
android:layout_toEndOf="#+id/price2" />
</LinearLayout>

TextView in relative layout doesn't expand to fill available space

why does the gray box (transaction_amount) in the following layout doesn't expand to full space available even though the layout:height is match parent for it.
<TextView android:id="#+id/transaction_amount"
android:layout_width="120dp"
android:layout_height="match_parent"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Large"
android:textColor="#android:color/primary_text_light"
android:background="#drawable/rounded_rectangle"
tools:text="100"/>
<TextView
android:id="#+id/transaction_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/transaction_amount"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"
android:textColor="#android:color/secondary_text_light"
tools:text="Mast Kalandar Dinner"/>
<TextView
android:id="#+id/shared_bw_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/transaction_name"
android:layout_toRightOf="#+id/transaction_amount"
android:layout_below="#id/transaction_name"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:textColor="#android:color/secondary_text_light_nodisable"
android:text="Shared Between"/>
<TextView
android:id="#+id/shared_bw_csv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/shared_bw_label"
android:layout_alignBaseline="#id/shared_bw_label"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:textColor="#android:color/secondary_text_light_nodisable"
tools:text="Ashu, Amol"/>
Try this layout instead, im sure it will help you.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:background="#ffa"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>

Android Textview not showing multiple lines within a list

May be this is a duplicate question,but I am asking it again because the solutions here is not working for me.I have a listview and within the list view I have 2 imageviews and a textview.Refer to the image below:
As you can see I cannot split the textviews into 2 lines and as a result my textview is overlapping with that of the imageview.Here is my code:
uplodefilelist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_filelist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="20dp"
android:paddingTop="20dp" >
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/default_avatar" />
<RelativeLayout
android:id="#+id/ll_cntactcont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/fileimage" >
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
/>
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/settings"
android:textColor="#000000"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
</RelativeLayout>
I cannot use any html format within the setText() method or I cannot do anything from java file.I have to do it from within the xml file only.I consulted our very own stack overflow and added this lines in my textview.
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
But as you can see the image none of them are working.Help.
just add 1 tag in to Textview That
android:layout_toLeftOf="#+id/btnSettings"
So this old one is
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"/>
Change to :
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:layout_toLeftOf="#+id/btnSettings"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"/>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center">
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:adjustViewBounds="true"/>
<LinearLayout
android:id="#+id/ll_cntactcont"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp">
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"/>
</LinearLayout>
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:textColor="#000000"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_marginLeft="5dp"/>
</LinearLayout>
add android:layout_toLeftOf="#+id/btnSettings" in your textview as
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
android:layout_toLeftOf="#+id/btnSettings"
/>
And don't forget to clear the project.
Add android:layout_toLeftOf="#+id/btnSettings" in textview and remove its parent relative layout
try this layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_filelist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="20dp"
android:paddingTop="20dp" >
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/default_avatar" />
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/btnSettings"
android:layout_toRightOf="#+id/fileimage"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="#drawable/settings"
android:textColor="#000000" />
</RelativeLayout>
you just have to add one line to your TextView
android:layout_toLeftOf="#+id/btnSettings"
Try this Code...
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/default_avatar" />
<RelativeLayout
android:id="#+id/ll_cntactcont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/fileimage" >
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee "
android:layout_toLeftOf="#+id/btnSettings" <!-- use this for setting textview properly -->
android:textColor="#000000"
android:lines="2" <!-- put this line if you always want to show 2 lines -->
android:textStyle="bold"
android:maxLines="2" <!-- max number of size... used when text is long -->
/>
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/settings"
android:textColor="#000000"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
Your textview needs to be a specific width for it to wrap not wrap content. You probably want to do a LinearLayout and not Relative for those 3 views.

Android: Tablelayout with relative layouts contained within?

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" />

Categories

Resources