I want to highlight item clicked on custom listview. I tried different options but not of them are working. Can someone tell me what's wrong?
my custom listview com.foo.ViewEditListView extends ListView implements android.widget.AdapterView.OnItemLongClickListener
list_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:layout_alignParentBottom="true"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView_list_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
>
</TextView>
<EditText
android:id="#+id/searchQueryText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:drawableRight="#drawable/search"
android:hint="Search Expenses by Amount"
android:textColorHint="#5e8e19"
android:inputType="numberSigned|numberDecimal"
style="#android:style/TextAppearance.Small"
>
</EditText>
<com.foo.ViewEditListView
android:id="#+id/viewExpenseListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#/drawable/list_selector_bg" //doesn't work
/>
</LinearLayout>
list_row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#/drawable/list_selector_bg" //doesn't work
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/v_row_field1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#C11B17"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/v_row_field2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:layout_marginRight="2dp" />
</RelativeLayout>
</LinearLayout>
list_selector_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:drawable="#android:drawable/list_selector_background" />
</selector>
I also tried to setSelector in Activity but none of them are working. Right now, i am clueless. Can someone help me here?
If i put android:background="#/drawable/list_selector_bg" into RelativeLayout, it highlights only that portion. But i want whole layout to be highlighted.
Thanks
CP
Have custom drawable set as background for the layout. Modify the below according to your needs. When pressed you will have different background and on release will return to the default state.
In your list_row.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:layout_alignParentBottom="true"
android:background="#drawable/listbkg" // set backcground
android:orientation="vertical"
>
....
</LinearLayout>
listbkg.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/pressed" /> //pressed state
<item android:state_focused="false"
android:drawable="#drawable/normal" /> // normal state
</selector>
pressed.xml in drawable fodler
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF1A47"/> //background color
<stroke android:width="3dp" // border color
android:color="#0FECFF"/>
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp" //for rounded corners
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
normal.xml in drawable folder
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/> // change olor
<stroke android:width="3dp" // for border color
android:color="#0FECFF" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp"// for rounded corners
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
Edit:
You can also include gradient as you can see the same in the snap shot.
In getView() of custom adapter
convertView =mInflater.inflate(R.layout.list_row, parent,false);
// inflating custom layout
Then in list_row.xml set the background for the root layout.
Resulting Snap Shot
When pressed it highlights the layout and on release will go back to normal state.
1) If you want highlight selected items you can handle it by using your CustomAdapter. But it's not very good way:)
2) I think, the best way is use common Android implementation of Checkable interface for your view (as example):
public class CheckableFrameLayout extends FrameLayout implements Checkable {
private boolean mChecked;
public CheckableFrameLayout(Context context) {
super(context);
}
public CheckableFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setChecked(boolean checked) {
mChecked = checked;
setBackgroundDrawable(checked ? new ColorDrawable(0xff0000a0) : null);
}
public boolean isChecked() {
return mChecked;
}
public void toggle() {
setChecked(!mChecked);
}
}
OR
3) Use CheckedTextView
You can found example in Android Samples named as ApiDemos (ListView with multichoice).
UPDATE:
Don't forget that your ListView must have ChoiceMode != ListView.CHOICE_MODE_NONE
Put CheckableFrameLayout into your package and rewrite your list_row.xml like this:
<com.foo.CheckableFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_selector_bg"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/v_row_field1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#C11B17"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/v_row_field2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:layout_marginRight="2dp" />
</RelativeLayout>
</com.foo.CheckableFrameLayout>
If you want get states for your CheckableFrameLayout from statelist (be setting it to background), then you need to override your list_selector_bg.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="#android:drawable/list_selector_background" />
</selector>
And rewrite CheckableFrameLayout for working with it. I have not done it correctly in haste (I don't know why it change highlight correctly only afer second tap). But you can take this code and improve it (maybe using code of CheckedTextView can help you):
public class CheckableFrameLayout extends FrameLayout implements Checkable {
private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_checked
};
private boolean mChecked;
public CheckableFrameLayout(Context context) {
super(context);
}
public CheckableFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
}
return drawableState;
}
#Override
public void setChecked(boolean checked) {
mChecked = checked;
// setBackgroundDrawable(checked ? new ColorDrawable(0xff0000a0) : null);
}
#Override
public boolean isChecked() {
return mChecked;
}
#Override
public void toggle() {
setChecked(!mChecked);
}
}
Related
How to select the only 1 button out of 3 button? I manage to set/unset the background color on selected button for currently. But not able to select the only one selected button.
Example btn1, btn2, btn3.
When I selected btn1, the btn1 background was change color, and btn2 and btn3 not affected. After that when I selected the btn2 again, the btn1 background color was unset and the btn2 background was change color. So at this time the btn2 is selected and btn1 and btn3 not selected.
Below is my sample code:
public class ViewHolder extends RecyclerView.ViewHolder {
Button mButton;
public ViewHolder(View v) {
super(v);
parentActivity.runOnUiThread(new Runnable() {
#Override
public void run() {
mButton= itemView.findViewById(R.id.mButton);
}
});
}
}
holder.mButton.setOnClickListener(new DebouncedOnClickListener(500) {
#Override
public void onDebouncedClick(View v) {
if(!holder.mButton.isSelected()){
holder.mButton.setSelected(true);
setSelectedButton(holder);
}
else{
holder.mButton.setSelected(false);
setSelectedButton(holder);
}
}
});
private void setSelectedButton(ViewHolder holder){
if(holder.mButton.isSelected()){
holder.mButton.setBackgroundColor(parentActivity.getResources().getColor(R.color.unread_notification));
}
else{
holder.mButton.setBackgroundColor(parentActivity.getResources().getColor(R.color.white));
}
}
What you need is to implement selection into your RecyclerView. After some searching, I found that this website might be useful for you
https://medium.com/#maydin/multi-and-single-selection-in-recyclerview-d29587a7dee2
I suggest you to use CheckBox instead of buttons like this -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/background"
android:orientation="horizontal">
<RadioButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_background"
android:button="#null"
android:gravity="center"
android:text="Button 1"
android:textColor="#fff"
android:checked="true"
android:textStyle="bold" />
<RadioButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_background"
android:button="#null"
android:gravity="center"
android:text="Button 2"
android:textColor="#fff"
android:textStyle="bold" />
<RadioButton
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_background"
android:button="#null"
android:gravity="center"
android:text="Button 3"
android:textColor="#fff"
android:textStyle="bold" />
</RadioGroup>
And for the Button background -
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<shape android:shape="rectangle" >
<corners android:radius="50dp"/>
<solid android:color="#c7c7c7"/>
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="rectangle" >
<corners android:radius="50dp"/>
<gradient android:startColor="#79ccff"
android:endColor="#7900ca"/>
</shape>
</item>
</selector>
And for the background -
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="#c7c7c7" />
</shape>
I tried to customize spinner as follows where image is a 9 patch image.
<Spinner
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="#+id/spinner"
android:textSize="20sp"
android:background="#drawable/image"
/>
The result is this: Spinner screenshot
The text is completely hidden by the image. How to make the text visible?
Edit:
I verified that I can see the text on spinner if I use the image1. But if I use this image2 (created by yours truly) then I cannot see the text. Seems something is wrong with my 9 patch image. But I can't figure out what ?
try this code
layout:-
<Spinner
android:id="#+id/endmonthsp"
android:layout_width="140dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center" />
Activity:-
ArrayList<String> month = new ArrayList<String>(Arrays.asList("Month",
"January", "February", "March", "April", "May", "june", "July",
"August", "September", "October", "November", "December"));
Spinner spinner5 = (Spinner) findViewById(R.id.endmonthsp);
startdatemonthadapter = new DateAdapter(this, R.layout.spinnerlayout,
month);
spinner1.setAdapter(startdatemonthadapter);
startdatemonthadapter
.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
Adapter:-
public class DateAdapter extends ArrayAdapter<String> {
public DateAdapter(Context context, int resource, List<String> objects) {
super(context, resource, objects);
// TODO Auto-generated constructor stub
this.context = context;
}
private Context context;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = convertView;
if (view == null) {
LayoutInflater inflate = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflate.inflate(R.layout.spinnerlayout, null);
}
TextView spinneritemTV = (TextView) view
.findViewById(R.id.spinneritemTV);
spinneritemTV.setText(getItem(position));
return view;
}
}
spinnerlayout:-
<?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="200dp"
android:layout_marginBottom="50dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="50dp" >
<TextView
android:id="#+id/spinneritemTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:padding="10dp"
android:text="Testing "
android:textColor="#868A8D"
android:textSize="18sp" />
</RelativeLayout>
You need to set background of spinner as follows:
In your layout xml :
<Spinner
android:id="#+id/spinner1"
style="#style/spinner_style"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_height="45dp" />
Now in style.xml add a style for spinner as follows:
` <style name="spinner_style">
<item name="android:background">#drawable/spinner_bg</item>
<!--
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
-->
<item name="android:paddingLeft">5</item>
</style>`
Now make a xml named spinner_bg.xml in drawable :
`
<item><layer-list>
<item><shape>
<gradient android:angle="90" android:endColor="#android:color/transparent" android:startColor="#android:color/transparent" android:type="linear" />
<padding android:left="2dp" android:right="2dp" />
</shape></item>
<item>
<bitmap android:gravity="center_vertical|left" android:src="your background drawable for spinner here" />
</item>
</layer-list></item>
`
According to your question, below part of spinner_bg.xml did the trick.
`<item>
<bitmap android:gravity="center_vertical|left" android:src="your background drawable for spinner here" />
</item>`
Thats it.
There is really nothing wrong in setting the spinner background directly as I have done. Of course you cannot have different "states" of the spinner then. The text was not visible because the 9 patch image was corrupted for some unknown reason. I recreated the image and I can see the text on the spinner now. One more thing: the text will not be visible if "content areas" are not defined on the 9 patch.
I want to add badge notification to my arraylist.But I couldn't find a tutorial for this.This is my list code:
public void chatList() {
conversationsAdapter=new ArrayAdapter<JsonObject>(this,0) {
#Override
public View getView(int c_position,View c_convertView,ViewGroup c_parent) {
if (c_convertView == null) {
c_convertView=getLayoutInflater().inflate(R.layout.random_bars,null);
}
JsonObject user=getItem(c_position);
String name=user.get("name").getAsString();
String image_url="http://domain.com/profile/thumb/"+user.get("photo").getAsString();
TextView nameView=(TextView)c_convertView.findViewById(R.id.tweet);
nameView.setText(name);
ImageView imageView=(ImageView)c_convertView.findViewById(R.id.image);
Ion.with(imageView)
.placeholder(R.drawable.twitter)
.load(image_url);
return c_convertView;
}
};
ListView conversationsListView = (ListView)findViewById(R.id.conversationList);
conversationsListView.setAdapter(conversationsAdapter);
conversationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
startChat(conversationsAdapter.getItem(position));
}
});
}
My list:
I want to add badge to this list.How can I do this ?
Ps:I found a library https://github.com/jgilfelt/android-viewbadger but I don't want to use it.
Inflate the layout in custom listview which extends base adapter instead of array adapter. Add following layout into the custom list item layout.
drawer_list_item.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="48dp"
android:background="#drawable/list_selector">
<ImageView
android:id="#+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="#string/desc_list_item_icon"
android:src="#drawable/ic_home"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#id/icon"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#color/list_item_title"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
<TextView android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/counter_bg"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:textColor="#color/counter_text_color"/>
</RelativeLayout>
Use below drawable for background textview counter and set notification count value in textview
counter_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- view background color -->
<solid android:color="#color/counter_text_bg" >
</solid>
<!-- If you want to add some padding -->
<padding
android:right="3dp"
android:left="3dp" >
</padding>
<!-- Here is the corner radius -->
<corners android:radius="2dp" >
</corners>
</shape>
I have a customised Layout for a ListView, hosted in a Navigation Drawer. Here's the Layout for the adapter:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="100dp" >
<ImageView
android:id="#+id/icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:duplicateParentState="true"
android:src="#drawable/nav_drawer_icon_states" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/icon"
android:duplicateParentState="true"
android:text="#string/hello_world"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#drawable/nav_drawer_text_states" />
</RelativeLayout>
In my /res/drawable folder I have the nav_drawer_text_states.xml as:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#color/blue"/>
<item android:state_enabled="true" android:state_focused="true" android:state_window_focused="true" android:color="#color/white"/>
<item android:color="#color/gray"/>
</selector>
and have tested with simple selector as this too:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#color/blue" />
<item android:state_selected="true" android:color="#color/white" />
<item android:state_checked="true" android:color="#color/white" />
<item android:color="#color/gray" />
</selector>
The pressed and default color works, but the intermediate state, when I have selected an item the ListView:
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cacheColorHint="#00000000"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:paddingTop="?attr/actionBarSize" />
with the code:
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
doesn't change the selected text to white.
Any help is appreciated.
UPDATED
I changed the nav_drawer_text_states.xml to:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#color/pink"/>
<item android:state_activated="true" android:color="#android:color/white"/>
<item android:color="#color/second_row_playlists"/>
</selector>
and it worked, BUT the state_activated="true" is API11+ and my app is API8+.
Any help is appreciated.
< rant > Unfortunately Android is really bad in pre-Honeycomb versions, and the market don't want to let these versions die. < / rant >
I solved by doing by hand everything in an Adapter. If anyone still cares, here's the solution:
public class NavigationAdapter extends ArrayAdapter<String> {
private int mSelectedPosition;
public NavigationAdapter(Context context, String[] items) {
super(context, R.layout.cell_navigation_drawer, items);
this.mSelectedPosition = 0;
}
public void setItemChecked(int position) {
mSelectedPosition = position;
notifyDataSetChanged();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
...
}
...
Resources res = getContext().getResources();
if (position == mSelectedPosition) {
textView.setTextColor(res.getColor(R.color.white));
} else {
textView.setTextColor(res.getColor(R.color.gray));
}
return convertView;
}
}
and changed the method when clicked to:
public void setItemChecked(int position, boolean value) {
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
mMyAdapter.setItemChecked(mCurrentSelectedPosition);
}
I have just upgraded on Android 4.2 on my Galaxy Nexus and ListView seems to be slower than It used to be on 4.1. This bindView method was perfect fast on 4.1, on new 4.2 I see small glitches. I have tried to explicitly enable hardware acceleration in AndroidManifest.xml, but it dit not help much. People (Contacts) app works perfect on 4.2, which I guess is also implemented by extended android.support.v4.widget.CursorAdapter. I have also already tried to change android.support.v4.widget.CursorAdapter for android.widget.CursorAdapter without visible improvement.
#Override
public void bindView(View view, Context context, Cursor cursor) {
final ViewHolder holder = (ViewHolder) view.getTag();
holder.nameView.setText(cursor.getString(mStreetColumnIndex));
holder.townView.setText(cursor.getString(mTownColumnIndex));
if (mDistanceColumn != null) {
float distance = cursor.getFloat(mDistanceColumn);
String distanceUnit;
if (distance >= 1000) {
distance /= 1000;
distanceUnit = " km";
} else {
distanceUnit = " m";
}
String decimalString = mDecimalFormat.format(distance);
holder.distanceView.setText(decimalString + distanceUnit);
holder.distanceView.setVisibility(View.VISIBLE);
} else {
holder.distanceView.setVisibility(View.GONE);
}
// read only brand first letter to be faster
cursor.copyStringToBuffer(mBrandColumnIndex, mBuffer);
if (mBuffer.sizeCopied > 0) {
if (mBuffer.data[0] == 'a') {
holder.logoImgView.setImageResource(R.drawable.agip);
} else {
holder.logoImgView.setImageResource(R.drawable.papoil);
}
} else {
holder.logoImgView.setVisibility(View.INVISIBLE);
}
}
EDIT: added 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"
android:minHeight="#dimen/row_height"
android:background="#drawable/bg_list_selector"
android:layout_marginRight="#dimen/screen_padding"
android:layout_marginLeft="#dimen/screen_padding"
android:paddingLeft="#dimen/screen_padding">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="#dimen/screen_padding"
android:layout_toLeftOf="#+id/txtDistance"
android:orientation="vertical"
>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/list_text_primary_size"
android:textStyle="bold"
/>
<TextView
android:id="#+id/txtTown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/list_text_primary_size"
/>
</LinearLayout>
<TextView
android:id="#+id/txtDistance"
android:layout_toLeftOf="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#color/grey_dark"
android:textSize="13sp"
android:textStyle="bold"
android:layout_marginRight="#dimen/screen_padding"/>
<ImageView
android:id="#+id/imgLogo"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/agip"
android:background="#color/grey_dark"
/>
</RelativeLayout>
EDIT 2:
here is traceview http://goo.gl/UmS3w
which was made using http://goo.gl/Yoe1u
It was caused by too much complicated windowBackground, which was:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bg_repeat">
</item>
<item>
<shape>
<gradient android:startColor="#0affffff" android:endColor="#0a000000"
android:type="radial" android:gradientRadius="500"/>
</shape>
</item>
<item>
<shape>
<gradient android:startColor="#1effffff" android:endColor="#1e000000"
android:type="linear" android:angle="270"/>
</shape>
</item>
</layer-list>
and bg_repeat.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bg"
android:tileMode="repeat"/>
Thanks all for help!