简体   繁体   English

圆角ListView项目Android 4.0.4中的背景问题

[英]Rounded corner listview items Background issue in android 4.0.4

I have a listview code given below 我在下面给出了一个listview代码

        <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 注意:我的相对布局中的android:background =“ @ drawable / listview_bg”

here is the code of listview_bg.xml 这是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 在Android 4.0 Qmobile上输出黑色

在此处输入图片说明

Look the whole background of listview items became black. 看起来listview项的整个背景变成黑色。

while in Andorid 4.4.2 nexus 7 device and emulator I m getting the desired out come ie 而在Andorid 4.4.2 nexus 7设备和仿真器中,我得到了想要的结果,即

在此处输入图片说明

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: 将以下内容添加到您的listview_bg.xml中:

<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 将此添加到您的listview_bg.xml中

<solid
        android:color="color" />

Adding solid to you shape xml will fill your shape with your desire color 向您的实体添加形状xml将用您想要的颜色填充您的形状

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 使用以下drawable获得所需的输出,因为您在列表项的背景中缺少纯色,即为什么未获得所需的输出

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM