I have a listview code given below
<ListView
android:id="@+id/ListView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/RelativeLayout01"
android:cacheColorHint="@android:color/transparent"
android:choiceMode="singleChoice" >
</ListView>
and here is the listview items 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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="5dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_bg" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imgRealstatePhoto"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/imageView1"
android:layout_toRightOf="@+id/imgRealstatePhoto"
android:orientation="vertical" >
<TextView
android:id="@+id/txtRealstateAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#7D7D7D"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtRealstateHomeTypeBroker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="3"
android:text="Loading...."
android:textColor="#867C7D"
android:textScaleX="1.025"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/linearLayout1"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/linearLayout1"
android:gravity="bottom"
android:orientation="horizontal" >
<TextView
android:id="@+id/txtRealstatePrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:textColor="#006B9E"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtRealStateStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/real_estate_text_bg_pending"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="12sp" />
</LinearLayout>
<ImageView
android:id="@+id/imgRealstatePhoto"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:scaleType="centerCrop"
android:src="@drawable/ellectedofficialsoverlay" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/expand_ico" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Note: android:background="@drawable/listview_bg" in my relative layout
here is the code of listview_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="12dp" />
<stroke
android:width="1dp"
android:color="#6DD8F9" />
</shape>
output on android 4.0 Qmobile All noir
Look the whole background of listview items became black.
while in Andorid 4.4.2 nexus 7 device and emulator I m getting the desired out come ie
I want the layout in 2nd image in all devices. How to resolve this issue
您可以使用andorid“ CardView”进行尝试。通过使用cardview,您可以轻松管理圆角。请检查此链接 。有什么可以帮助您的。谢谢
Add to your listview_bg.xml this:
<solid
android:color="@android:color/transparent"/>
Try This Code :-
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp"
android:color="#ed4d44"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
You have different color on different device because each device have there own default theme thus giving that result.
Solution is to give background color to the relative layout so it is not transparent
Add this in your listview_bg.xml
<solid
android:color="color" />
Adding solid to you shape xml will fill your shape with your desire color
Use the below drawable to get the desired output,as you are missing solid color in the background of list itemsi.e why you are not getting desired output
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/white" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
<stroke
android:width="1dp"
android:color="#6DD8F9" />
// Try this way,hope this will help you to solve your problem.
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="1dp" android:color="#FFFFFF" />
<padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />
<corners android:radius="8dp" />
</shape>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.