9Patch content area error - android

It seems my content area doesn't match what the 9patch file says it should be
Heres my 9patch file.
and here is an image of how it looks with an item in it, but the text is getting cut off prematurely, it should be "Varenr." I don't understand why there is such a big white space instead of text ??
and here is the xml layout of the spinner:
<Spinner
android:id="#+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="#string/sort" />
And of the spinner item
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:gravity="center"
android:singleLine="true" />
Thanks in advance for help.
And for closure, the 9patch in question:
Edit:
The whole line where the spinner is located:
<LinearLayout
android:id="#+id/headerLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#color/transparent"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/sortAmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:singleLine="false"
android:textColor="#color/solid_red"
android:textSize="15dp" />
<TextView
android:id="#+id/sortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Produkter"
android:singleLine="true"
android:textColor="#color/solid_red"
android:textSize="15dp" />
</LinearLayout>
<Button
android:id="#+id/filterBtn"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="4"
android:background="#drawable/button_background_red"
android:clickable="true"
android:singleLine="true"
android:onClick="setFilterList"
android:text="Filtrér"
android:textColor="#color/solid_white"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:paddingRight="30dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="#string/sort" />
</LinearLayout>

Now, this is how I remade it:
Which gives this result:
Make sure the extension is .9.png
[EDIT]
This is the result when applied to a TextView:
The screen is an old ldpi device (240x320 #120 dpi)
This is how I applied it:
<?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/stripes_vert_4"
>
<!-- ... -->
<TextView
android:id="#+id/txtTitle3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentBottom="true"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"
android:text="Lorem ipsum dolor sit amet"
android:background="#drawable/spinner_drawable"
/>
</RelativeLayout>
[EDIT 2]
As per the OP requirement, I switched the TextView to a Spinner:
Result:
By using this 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="match_parent"
android:background="#drawable/stripes_vert_4"
>
<!-- ... -->
<Spinner
android:id="#+id/spnElements"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:entries="#array/prefs_search_modes"
android:layout_alignParentBottom="true"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"
android:background="#drawable/spinner_drawable"
/>
</RelativeLayout>
Which implies you have an arrays.xml file in your value folder.
Mine is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Settings -->
<!-- Word search mode -->
<string-array name="prefs_search_modes">
<item>*b* (Contains "b")</item>
<item>Ab* (Starts with "Ab")</item>
<item>*bc (Ends in "bc")</item>
<item>Abc (Exact match)</item>
</string-array>
</resources>
[EDIT3]
In the last comments the OP is asking for (75% white space + the rest of the width left for the spinner) something like this:
ARE YOU SURE?
The running screen is low res (ldpi).
But next to it, in the graphical editor you can see another device (HTC Desire Bravo) screen which is hdpi.
And it shows the same "issue": 1/4 screen width.
So, the stretchable part of the 9 png background (which contains the text) is squeezed away and only the unsqueezable part (the arrow) stays.
[EDIT4]
After playing with the 9 patch size, I could make part of the text become visible:
So, it seems you have to experiment with smaller sizes until you get an acceptable result.
[EDIT5]
I forgot to add the new spinner 9 patch (resized).
Here it is:
When rescaling, mind the outer border: it has to be completely transparent and the markers must be full black.

Related

ListView items gone off screen

The problem is when I run the program the view cuts like what shown in the picture above
I don't know what the exact sort of problem, so if you need anything to show just ask
I am using kotlin by the way
EDIT 1:
result_row.xml this is the XML for the row that shows in the ListView
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/itemName"
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="center"
android:text="Name"
android:textColor="#000000"
android:textSize="16sp" />
<View
android:id="#+id/lineView2"
android:layout_width="2dp"
android:layout_height="40dp"
android:background="#010101" />
<TextView
android:id="#+id/itemWeight"
android:layout_width="100dp"
android:layout_height="40dp"
android:gravity="center"
android:text="Item Weight"
android:textColor="#000000"
android:textSize="16sp" />
<View
android:id="#+id/lineView1"
android:layout_width="2dp"
android:layout_height="40dp"
android:background="#010101" />
<TextView
android:id="#+id/itemPrice"
android:layout_width="100dp"
android:layout_height="40dp"
android:gravity="center"
android:text="Price"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
</FrameLayout>
Your TextViews have fixed widths that total greater than the width of the screen:
android:layout_width="200dp"
...
android:layout_width="100dp"
...
android:layout_width="100dp"
Android phones can be as narrow as 320dp, so it'll get cut off. You need to modify your layout to use the available space, not hardcode fixed widths. Or, if you really want to use fixed widths, they need to be smaller (shouldn't add up to more than 320dp).
in your layout xml file edit
layout_width="0dp"
layoyt_height="0dp"

How to remove excessive line spacing of downloadable fonts?

I am investigating downloadable fonts (and fonts as resources) within my current Android application.
When I place fonts within the values/font folder they display as desired.
When I employ downloadable fonts they always have additional spacing between the lines.
I have to use android:lineSpacingMultiplier="0.5" within my layout xml to achieve the desired spacing.
I am applying the fonts to a textview and allowing it to wrap content.
I am concerned that using android:lineSpacingMultiplier may "clip" some characters.
What am I doing (or not doing) to create this text spacing issue?
Here's my layout xml:
<?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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/lexie_readable_regular"
android:padding="4dp"
android:text="#string/testing"
android:textColor="#color/daynight_textColor"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/inknut_antiqua_light"
android:padding="4dp"
android:text="#string/testing"
android:textColor="#color/daynight_textColor"
android:textSize="18sp"
android:textStyle="normal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/tiresias_infofont"
android:padding="4dp"
android:text="#string/testing"
android:textColor="#color/daynight_textColor"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/aphont_regular_q15c"
android:padding="4dp"
android:text="#string/testing"
android:textColor="#color/daynight_textColor"
android:textSize="18sp" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="CLICK ME"
android:textColor="#color/daynight_textColor" />
<ImageView
android:id="#+id/imageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:src="#drawable/placeholder" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtNightMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:fontFamily="#font/tiresias_infofont"
android:paddingRight="8dp"
android:text="Night Mode"
android:textColor="#color/daynight_textColor" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/switchCompat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:checked="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:theme="#style/MySwitch" />
</LinearLayout>
</LinearLayout>
The "downloadable" font is
android:fontFamily="#font/inknut_antiqua_light"
All the others are fonts I have manually placed in the /font folder.
And here is a screenshot of the issue:
This downloadable font looks OK
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Actor"
app:fontProviderCerts="#array/com_google_android_gms_fonts_certs">
</font-family>
while this one has the issue shown above:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="name=Inknut Antiqua"
app:fontProviderCerts="#array/com_google_android_gms_fonts_certs">
</font-family>
What is the difference?
I've tried using android:includeFontPadding="false"; it does not have the desired effect.
This is probably sinful of me but I was desperate to solve the line spacing issue, and adding a negative value to lineSpacingExtra seemed to work:
android:lineSpacingExtra="-4sp"
For the "font padding" on the top and bottom of the TextView, you can use
android:includeFontPadding="false"
I've tested on Android 5.1.1 & 7.0.
Fyi, I'm using sp because this is dealing with fonts.
UPDATE: Your font "inknut_antiqua_light" has the issue with large empty space. Other fonts are works without this issue. You can check the font space
below:
You can try removing font paddings by adding this line to your desired TextView
android:includeFontPadding="false"
Like this:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/inknut_antiqua_light"
android:padding="4dp"
android:includeFontPadding="false"
android:text="#string/testing"
android:textColor="#color/daynight_textColor"
android:textSize="18sp"
android:textStyle="normal" />
Use following attributes:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.0"
android:includeFontPadding="false"/>

Content goes off screen in Android 4.1.1

i noticed recently when i checked my app in android 4.1.1 that my content goes off the screen but works very well in 4.2.2 above. Please check the screenshot.
and yes, its a bilingual app (English/Tamil). After few research i found out that English ListItem works well but Tamil causes problem
Layout Code :
activity_latest_news.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".LatestNews" >
<ListView
android:id="#+id/LatestNewsView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</ListView> </RelativeLayout>
latest_news_single_view.xml
<?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="match_parent" >
<TextView
android:id="#+id/LatestNews_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/latest_news_dummy_title"
android:textSize="15sp" />
<TextView
android:id="#+id/LatestNews_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#id/LatestNews_title"
android:text="#string/latest_news_dummy_desc"
android:textColor="#color/getCCC"
android:textSize="14sp" />
<TextView
android:id="#+id/LatestNews_posted_on"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/LatestNews_description"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:text="#string/latest_news_posted"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#911991" />
<ImageView
android:id="#+id/latest_news_addfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/LatestNews_posted_on"
android:src="#drawable/star"
android:layout_alignParentRight="true" />
</RelativeLayout>
Is this Unicode issue? or layout problem?
And also please take a look at both emulator. if u notice, in 4.1.1 the theme is like greyish white while in 4.2.2 is complete white.. and even the drawable (refresh image) is looking weird (Yea, i know i haven't setup separate drawable for mdpi,hdpi etc) But what causes the difference? Is this App Theme issue?
Any help will be much appreciated. Thank you!
Try changing your layouts as below and check what happens.
your listview layout :
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LatestNewsView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
Row 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="wrap_content" >
<TextView
android:id="#+id/LatestNews_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/latest_news_dummy_title"
android:textSize="15sp" />
<TextView
android:id="#+id/LatestNews_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/LatestNews_title"
android:text="#string/latest_news_dummy_desc"
android:textColor="#color/getCCC"
android:textSize="14sp" />
<TextView
android:id="#+id/LatestNews_posted_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LatestNews_description"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:text="#string/latest_news_posted"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#911991" />
<ImageView
android:id="#+id/latest_news_addfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/LatestNews_posted_on"
android:src="#drawable/star"
android:layout_alignParentRight="true" />
</RelativeLayout>
Image problem:
as you can see one emulator is Nexus S and one is Nexus One so there is a difference in their ppi values which is causing the problem. you need to set appropriate image for corresponding density.
Update :
check this it may help
Try and manually specify the number of lines for each text view. For instance, change the first TextView to look like this:
<TextView
android:id="#+id/LatestNews_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:singleLine="false"
android:maxLines="3"
android:ellipsize="end"
android:text="#string/latest_news_dummy_title"
android:textSize="15sp" />
Note that I added:
android:singleLine="false" <!-- Allows content to wrap into other lines -->
android:maxLines="3" <!-- Makes maximum no. of line wraps = 3 -->
android:ellipsize="end" <!-- Adds an ellipsis (...) to the end of line-->
Side note: you're mixing fill_parent and match_parent. They do the same thing. For more consistency, stick to match_parent.
EDIT: Also, get rid of layout_alignParentRight="true". I don't think you need it because the width is already going to fill the parent view. Using layout_alignParentLeft="true" is sufficient since both English and Tamil are written left-to-right.

Android - RelativeLayout with image and text, design problems

I have a relative layout with an image and two textviews (one for the news title and the other one for the date). I put a hardcoded value for the width of the textview with the title. If I use wrap content it overlaps the date.
Here's my xml 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:orientation="horizontal"
android:padding="5dp" >
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp"
android:padding="3dp" >
<ImageView
android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/internet"
android:contentDescription="News" />
</LinearLayout>
<TextView
android:id="#+id/txtTitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail"
android:text="Timberlake's fourth studio album The 20/20 Experience – 2 of 2 was released on September 30, 2013."
android:textSize="14sp" />
<TextView
android:id="#+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/txtTitle"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="23.09.2013"
android:textColor="#C0C0C0"
android:textSize="10sp" />
</RelativeLayout>
For the screen size 4,7 it looks like this:
screen size 4,7
But for the screen size 5,1 it looks bad:
screen size 5,1
My goal is that I have the same look for each screen size.
The space between the title and the date should always be the same.
How can I achieve this?
You're already using a RelativeLayout, so surprisingly there is a quick fix for you here. Leave your TextView's width as match_parent, but what you want to do is sandwich it between the ImageView and the TextView you use for your date. Try doing the following (note that I have to switch the order of the TextViews in your layout to make this work).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp"
android:padding="3dp" >
<ImageView
android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="News" />
</LinearLayout>
<!-- Note: I switched txtDate and txtTitle in your layout file ONLY -->
<!-- This will NOT change their order in your actual view -->
<TextView
android:id="#+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/txtTitle"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="23.09.2013"
android:textColor="#C0C0C0"
android:textSize="10sp" />
<!-- This is the important part, note the android:layout_toLeftOf -->
<!-- Also remember to change the width back to "wrap_content -->
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail"
android:layout_toLeftOf="#id/txtDate"
android:text="Timberlake's fourth studio album The 20/20 Experience – 2 of 2 was released on September 30, 2013."
android:textSize="14sp" />
</RelativeLayout>
This should give you your desired view.
Hope this helps. Good luck and happy coding!

ListView displaying problems

I have a listview that consists three columns. The first one is an ImageView, the second and third one are textviews (see code blow).
I want the list to be aligned like this:
the icon and the date should always been shown completely !!
the text in the middle should show as much chars as possible
the date should always be on the right of the right side
With the XML below it looks ok on my Nexus 4. But on the asus tablet the date should be more on the right and the coloumn in the middle should show more text (screenshot 1). On the AVD (screenshot 2) the coloumn in the middle should be smaller and the date should be shown completely.
Can anyone tell me how to change the XML? Thanks!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="50px"
android:layout_height="50px"
android:layout_marginLeft="5px"
android:layout_marginRight="20px"
android:layout_marginTop="5px"
android:src="#drawable/social_chat"
android:layout_weight="0"
>
</ImageView>
<TextView
android:id="#+id/label"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="0px"
android:text="#+id/label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="50"
android:maxLines="1"
android:singleLine="true"
>
</TextView>
<TextView
android:id="#+id/last_changed"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="15px"
android:layout_marginLeft="5px"
android:text="#+id/last_changed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="50"
android:maxLines="1"
android:singleLine="true"
>
</TextView>
Off the top of my head your layout would look something like this.-
<?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:padding="5dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:src="#drawable/social_chat" />
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1"
android:singleLine="true" />
<TextView
android:id="#+id/last_changed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="5dp"
android:text="#+id/last_changed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true" />
</LinearLayout>
The key here is to use wrap_content for the views that just need to keep their size, and set a weight for the middle view, which you want to fill the rest of the row.
Some useful tips.-
fill_parent is deprecated, use match_parent instead
When a view has no children, you can just close it with />
singleLine="true" is enough to have a singleLined TextView
You'll usually want to use dp units instead of px
This should do your job. I have put the imageview on the parents left, the date on the parents right and the label to the rightof image and to the left of date.It should work fine for you. Margins , padding please put yourself
<?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:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/social_chat" />
<TextView
android:id="#+id/last_changed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true" />
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_toLeftOf="#id/last_changed"
android:layout_toRightOf="#id/logo"
android:singleLine="true" />
</RelativeLayout>

Categories

Resources