ListView Item appear strange drawable - android

I have a poblem when custom progress bar. I create a animaiton drawable for progressbar. After I set this drawable for progressbar when dialog loading data show.
File anim_loading.xml
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/icon_loading"
android:pivotX="50%"
android:pivotY="50%" />
After I set this drawable for dialog loading data.
public void showProgressDialog(String content, boolean cancleable) {
progressDlg = ProgressDialog.show(this, "", content, true, true);
progressDlg.setIndeterminateDrawable(getResources().getDrawable(R.drawable.anim_loading));
progressDlg.setCancelable(cancleable);
progressDlg.setOnCancelListener(this);
}
But in android 2.2x or 2.3x Listview appear drawable icon_loading in row of data. I can't undestand .. :(
I attached two file (image). Correctly with android 4.0, and error with android 2.3 or 2.2
Layout row :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/menu_item_selector"
android:paddingBottom="4dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="4dp" >
<TextView
android:id="#+id/txtCode"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:textColor="#color/RED_COLOR"
android:textSize="25.0sp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/layoutInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dip"
android:layout_toRightOf="#id/txtCode"
android:padding="1.0dip" >
<LinearLayout
android:id="#+id/llContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#color/BLACK_COLOR"
android:textStyle="bold" />
<ImageView
android:id="#+id/ivFavorite"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:contentDescription="#string/app_name"
android:src="#drawable/icon_love_small" />
</LinearLayout>
<TextView
android:id="#+id/txtDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/llContent"
android:singleLine="true"
android:textColor="#color/BLACK_COLOR"
android:textSize="12.0sp"
android:textStyle="italic" />
</RelativeLayout>
</RelativeLayout>
Selector of row:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/SEA_BLUE" android:state_pressed="true"/>
<item android:drawable="#color/SEA_BLUE" android:state_focused="true"/>
<item android:drawable="#color/TRANSPARENT"/>
</selector>
Hope somebody help me find this bug.
Thanks so much!
p/s Sorry I hide content data in listview :)

This is a starnge problem. I just solved it but I can't explain the reason.
The point is at:
<item android:drawable="#color/TRANSPARENT"/>
You should not set the normal background of listview item to be transparent with android 2.3 or 2.2. Change the color and you will get correct result.

Related

Android: Setting View background using itemSelector with complex Views

We have a relatively simply Android item template on a ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="#android:drawable/list_selector_background">
<!--Encounter Type and Start-->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/mid_grey"
android:paddingTop="12dp"
android:paddingRight="24dp"
android:paddingBottom="12dp"
android:paddingLeft="24dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textStyle="bold"
android:textSize="#dimen/text_size_large"
android:text="Main Item Heading"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:45"
android:layout_toLeftOf="#+id/startTimeRelative"
android:textColor="#color/grey1"
android:textSize="#dimen/text_size_large" />
<TextView
android:id="#+id/startTimeRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12sp"
android:layout_alignParentRight="true"
android:text="Today"
android:textColor="#color/grey1"
android:textSize="#dimen/text_size_large" />
</RelativeLayout>
<!--Patient Name and Avatar-->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingRight="24dp"
android:paddingBottom="8dp"
android:paddingLeft="24dp">
<ImageView
android:id="#+id/patientAvatar"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:scaleType="fitXY"
android:src="#drawable/patient_avatar" />
<LinearLayout
android:layout_toRightOf="#+id/patientAvatar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/patientname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Subsection Heading"
android:textColor="#000000"
android:textSize="#dimen/text_size_large"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="1" />
</LinearLayout>
</RelativeLayout>
<!--</LinearLayout>-->
</LinearLayout>
That displays this layout
I want to set the background of the items when they are pressed or selected. I am trying to do this by setting the item's background to a custom item selector
android:background="#android:drawable/list_selector_background"
The is is the selector xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="#color/debug_blue" />
<item android:state_checked="true" android:drawable="#color/debug_green" />
<item android:state_pressed="true" android:drawable="#color/debug_blue" />
</selector>
The problem is that because I am setting the background colour's of Views within the item the Selector does not show through as expected. I have removed one of the inner colours (used in the "Subsection Heading" in the screenshot) and set that as the colour of the Listview. That means the blue shows through when the item is pressed on the lower part of the template, as seen in this screenshot
All the Android examples showing item selectors working with simple item layouts that have one or no background colour set.
How can I set the whole item's background whilst still having one or more background colours on child view's, when not selected?
I have looked at setting drawSelectorOnTop on the ListView but that did not help

Custom checkbox image - but can still see original?

I was using the standard Android checkbox, but when I installed my app on other peoples phones for testing, the checkbox was different on each phone.
On one of the phones, the checkbox was so light you could hardly see the box when it was checked.
So I tried to make a custom checkbox checked image.
This worked ok, but I can still see the original deafult checkbox image in the background?
Any ideas why?
Here is my checkable linear layout, to be honest I'm not even sure if I need this?
<?xml version="1.0" encoding="utf-8"?>
<com.myapp.myappname.CheckableLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox"
android:background="#drawable/customcheckbox"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</com.myapp.myappname.CheckableLinearLayout>
Then I have a custom list row which is my custom ListView:
<?xml version="1.0" encoding="utf-8"?>
<com.myapp.myappname.CheckableLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<!-- Thumbnail image -->
<LinearLayout android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="#+id/list_image"
android:layout_width="60dip"
android:layout_height="60dip"
android:focusable="false"
/>
</LinearLayout>
<!-- File Name -->
<TextView
android:id="#+id/filename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:textColor="#343434"
android:textSize="12dip"
android:layout_marginTop="10dip"
android:layout_toRightOf="#+id/thumbnail"
android:focusable="false"
android:text="Some Text." />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_alignParentRight="true"
android:background="#drawable/customcheckbox"
android:enabled="false" />
</RelativeLayout>
</com.myapp.myappname.CheckableLinearLayout>
Any ideas how to suppress the original?
Custom checkbox:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--<item android:state_checked="false" android:drawable="#drawable/unchecked" />-->
<item android:state_checked="true" android:drawable="#drawable/checked" />
<!--<item android:drawable="#drawable/unchecked" /> <!– default –>-->
</selector>
The attribute you want to change is button, not background.
First, design your custom graphics for different button states. Use a state list drawable (docs) to associate the various images. For example:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/checked" />
<item android:state_checked="false" android:drawable="#drawable/unchecked" />
</selector>
Save this into your drawable resources folder, something like my_checkbox.xml.
Now, use the button attribute on your checkbox layout definition:
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_alignParentRight="true"
android:button="#drawable/my_checkbox"
android:enabled="false" />

Android RelativeLayout Drawable Selector doesn't work

I have troubles making my RelativeLayout change background drawable on click. I made it clickable and focusable but this make nothing change. The background remains static to enables drawable. Thanks in advance.
<RelativeLayout
android:id="#+id/bttn_type_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:background="#drawable/day_bttn_bg_red"
android:clickable="true"
android:focusable="true"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<ImageView
android:id="#+id/bttn_type_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:contentDescription="#string/app_name"
android:src="#drawable/relationship" />
<TextView
android:id="#+id/bttn_type_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bttn_type_iv"
android:layout_centerHorizontal="true"
android:layout_marginTop="1dp"
android:text="#string/type_bttn_txt"
android:textSize="#dimen/data_fill_bttn_txt_size"
android:textStyle="bold" />
</RelativeLayout>
Here is the selector xml in drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bttn_red_p_bg" android:state_enabled="false" android:state_pressed="true"></item>
<item android:drawable="#drawable/bttn_red_a_bg" android:state_enabled="true"></item>
</selector>

List view item layout in Android

I'm trying to set the background of the right arrow, that when I press it, only the background around the arrow will shown(till the separator).
I tried to do it with Image Button but when I do it like this, the list item can't be clickable.
this is my XML item list layout:
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:paddingTop="5dip" >
<ImageView
android:id="#+id/itemlist_checkedd"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="#drawable/ic_checkitem" />
<ImageView
android:id="#+id/skinpreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/itemlist_checkedd"
android:scaleType="fitXY" />
<ImageButton
android:id="#+id/skinEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:paddingLeft="10dip"
android:background="#null"
android:src="#drawable/ic_go_edit" />
<ImageView
android:id="#+id/separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/skinEdit"
android:layout_marginRight="5dip"
android:src="#drawable/separator"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dip"
android:layout_marginRight="15dip"
android:layout_toRightOf="#id/skinpreview"
android:layout_toLeftOf="#id/separator"
android:textAppearance="?android:attr/textAppearanceLarge" />
This is how it looks:
Any suggestions???
Thanks.
Create selector xml file in res/drawable
<?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/arrow_pressed" />
<item
android:state_pressed="false"
android:drawable="#drawable/arrow" />
</selector>
You will need to create another picture of the arrow with the highlighted background you need.
of course then assign your ImageView src to the xml file (arrow_selector.xml) for example
Just set the background color or an image to the parent view in this xml

Ratings bar in android

I have an application that has a custom Ratings bar. The code for the same is below:
<LinearLayout style="#style/FillWrap.LL.Footer"
android:layout_width="fill_parent" android:weightSum="1">
<ImageView android:id="#+id/IV_Prev" android:src="#drawable/left_arrow"
style="#style/Wrap" android:layout_weight="0.35" />
<RatingBar android:id="#+id/RB_Stars" style="#style/Wrap"
android:progressDrawable="#drawable/ratings_bar" android:numStars="3"
android:layout_weight="0.3" android:stepSize="1" />
<ImageView android:id="#+id/IV_Next" android:src="#drawable/right_arrow"
style="#style/Wrap" android:layout_weight="0.35" />
</LinearLayout>
The code for the ratings_bar drawable is:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:drawable="#drawable/ic_swipe_fav_off_default"/>
<item android:id="#android:id/progress" android:drawable="#drawable/ic_swipe_fav_focused" />
</layer-list>
I'm able to see a proper rating bar with 3 stars in the portrait mode as below:
but in the landscape mode, the same becomes like
Can some one tell me why, and how can I circumvent this problem.
Thanks!
Try adding
android:layout_width="wrap_content"
android:layout_height="wrap_content"
into your < RatingBar >

Categories

Resources