Please take a look at the following layout. This layout is used in a TableView and is applied in each row. The question is why the button in each tablerow is only clickable in the upper half of the tableviewcell when transparency is applied.
Without transparency the button fills up the correct amount of space.
<?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:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageButton
android:id="#+id/btnSelect"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#color/white"
android:contentDescription="Geselecteerde rekening"
android:src="#drawable/checkbox_akkoord_uit" />
<ImageView
android:id="#+id/imgPhoto"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignBottom="#+id/btnSelect"
android:layout_marginLeft="4dp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/btnSelect"
android:scaleType="fitCenter"
android:src="#drawable/icon_foto" />
<ImageView
android:id="#+id/imgPencil"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignBottom="#+id/btnSelect"
android:layout_marginLeft="4dp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/btnSelect"
android:src="#drawable/potlood" />
<ImageView
android:id="#+id/ivDrag"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_centerVertical="true"
android:src="#drawable/settings" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dip"
android:layout_toLeftOf="#+id/ivDrag"
android:layout_toRightOf="#+id/imgPhoto"
android:orientation="vertical" >
<TextView
android:id="#+id/txtDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Medium Text Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/green"
android:textSize="#dimen/text_size_1" />
<TextView
android:id="#+id/txtProductname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/green"
android:textSize="#dimen/text_size_2" />
<TextView
android:id="#+id/txtAccountnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/green"
android:textSize="#dimen/text_size_3" />
</LinearLayout>
<Button
android:id="#+id/btnModify"
android:background="#android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/btnSelect"
android:layout_toLeftOf="#+id/ivDrag" />
Any help is greatly appreciated!
Regards, Raoul
Turns out that the Button needs a minimum height. So the altered XML definition could be:
<Button
android:id="#+id/btnModify"
android:background="#android:color/transparent"
android:minHeight="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/btnSelect"
android:layout_toLeftOf="#+id/ivDrag" />
This worked for me!
Regards, Raoul.
Related
Fairly new to Android dev, I'm having trouble with a RelativeLayout. In the following XML example, I would expect my ImageButton (on the right, with the '+') to match the RelativeLayout height. However, it doesn't, as shown on this image:
Why isn't the right button with the '+' matching the maximum possible height ?
Here's the related code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/artist_cell_background">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:src="#drawable/ic_music_note_24dp">
</ImageView>
<ImageButton
android:id="#+id/artist_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/artist_cell_playlist_button_background">
</ImageButton>
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button"
android:layout_below="#id/artist_name">
</TextView>
</RelativeLayout>
Thanks for any help or idea.
EDIT: What I want is the right button to occupy the height of the line, i.e. have the same height than the two text zones of the middle plus top and bottom margins, no more no less.
As I can understand from the XML, it seems you want to make the "+" button more clickable.
I would suggest you to have some padding and that should do the job.
EDIT 1 : You may do the following without padding, by aligning Top and Bottom of the ImageView to the relevant TextView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/artist_cell_background">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:src="#drawable/ic_music_note_24dp">
</ImageView>
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:paddingTop="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:paddingBottom="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button"
android:layout_below="#id/artist_name">
</TextView>
<ImageButton
android:id="#+id/artist_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignTop="#id/artist_name"
android:layout_alignBottom="#id/number_of_albums"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/artist_cell_playlist_button_background">
</ImageButton>
</RelativeLayout>
Put your relative layout inside a linear layout that should do it
<?xml version="1.0" encoding="utf-8"?>
<LinearLaout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/artist_cell_background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:src="#drawable/ic_music_note_24dp">
</ImageView>
<ImageButton
android:id="#+id/artist_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/artist_cell_playlist_button_background">
</ImageButton>
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button"
android:layout_below="#id/artist_name">
</TextView>
</RelativeLayout>
</LinearLayout>
Your image may be small. Use android:scaleType="fitCenter" in the ImageButton.
Also try removing default padding and margin from the ImageButton by setting them to 0dp.
With the help of #rex, I figured out how to do this: enclose the left picture and the 2 TextViews in a RelativeLayout (this sets the size of the main RelativeLayout), and align top and bottom the ImageButton to this layout.
The code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/artist_cell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/cell_background">
<ImageButton
android:id="#+id/artist_plus_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignTop="#+id/artist_infos"
android:layout_alignBottom="#+id/artist_infos"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/plus_button_background"
android:contentDescription="#string/artistPlusButtonCD">
</ImageButton>
<RelativeLayout
android:id="#id/artist_infos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/artist_plus_button"
android:layout_toStartOf="#id/artist_plus_button">
<ImageView
android:id="#+id/album_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_music_note_24dp"
android:contentDescription="#string/albumCoverContentDescription">
</ImageView>
<TextView
android:id="#+id/artist_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/album_cover"
android:layout_toEndOf="#id/album_cover">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#id/album_cover"
android:layout_toEndOf="#id/album_cover"
android:layout_below="#id/artist_name">
</TextView>
</RelativeLayout>
</RelativeLayout>
I make the single_row.xml for the custom adapter which works perfectly on several devices but in the case of HighEnd device , the TextVIew is slightly up from the center. Why ??Please Help..
Image Link to understand the question Clearly
single_row.xml
<?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"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageViewSingleRow"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/one"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:adjustViewBounds="true"
/>
<TextView
android:paddingTop="10dp"
android:paddingBottom="6dp"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title text here"
android:id="#+id/textViewTitle"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/imageViewSingleRow"
android:layout_toRightOf="#+id/imageViewSingleRow"
android:layout_toEndOf="#+id/imageViewSingleRow"
android:textSize="18dp"
android:gravity="center_vertical"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20sp"
android:textStyle="normal"
android:id="#+id/textViewNumbering"
android:layout_alignLeft="#+id/imageViewSingleRow"
android:layout_alignTop="#+id/imageViewSingleRow"
android:layout_alignRight="#+id/imageViewSingleRow"
android:layout_alignBottom="#+id/imageViewSingleRow"
android:gravity="center"
/>
<TextView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="description"
android:id="#+id/textViewDescription"
android:layout_below="#+id/textViewTitle"
android:layout_centerHorizontal="true" />
<TextView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="imageLink"
android:id="#+id/textViewImageLink"
android:layout_below="#+id/textViewDescription"
android:layout_alignRight="#+id/textViewDescription"
android:layout_alignEnd="#+id/textViewDescription"
/>
</RelativeLayout>
Finally done for the high end devices too..
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="1"
android:padding="26dp"
android:textStyle="bold"
android:id="#+id/textViewNumbering"
android:layout_alignTop="#+id/imageViewSingleRow"
android:layout_alignBottom="#+id/imageViewSingleRow"
android:gravity="center"
/>
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>
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.
I want to create a listview like older gmail app. See the screenshot:
I tried putting an empty view like this:
<TextView
android:id="#+id/color_highlight"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ff0000"
android:minHeight="48dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/color_highlight"
android:text="Mudit Agarwal"
android:textStyle="bold"
android:textColor="#242424"
android:textIsSelectable="false"
android:textSize="22sp" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/name"
android:layout_below="#id/name"
android:text="9933445566"
android:textColor="#777777"
android:textIsSelectable="false"
android:layout_marginBottom="10dp"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="3dp"
android:src="#drawable/contact" />
but this is not taking full height of the view. Please suggest.
What I changed is
android:layout_alignBottom="#+id/number"
to your color_highlight TextView. and instead of margin, I put padding like below in number TextView.
android:paddingBottom="20dp"
just put following layout code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/color_highlight"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/number"
android:background="#ff0000"
android:minHeight="48dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/color_highlight"
android:text="Mudit Agarwal"
android:textColor="#242424"
android:textIsSelectable="false"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/name"
android:layout_below="#id/name"
android:paddingBottom="20dp"
android:text="9933445566"
android:textColor="#777777"
android:textIsSelectable="false"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="3dp"
android:src="#drawable/contact" />
</RelativeLayout>
I'm not sure but you can try putting android:layout_height="0dip" instead of android:layout_height="match_parent".