应用样式到Android的ListView [英] Apply Style to Android ListView

查看:166
本文介绍了应用样式到Android的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的风格在lisview我的应用程序所看到的这个图片

I want to style the lisview in my application as seen is this image

我曾尝试通过应用梯度开发它:

I have tried to develop it by applying gradient :

$ C $下list_item_normal是:

code for list_item_normal is :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:centerColor="#E6E6E6"
        android:endColor="#CCCCCC"
        android:startColor="#FFFFFF" 
        android:angle="270"/>
    <!--
        <gradient
        android:startColor="#FF7500"
        android:centerColor="#FFCC00"
        android:endColor="#FF7500"
        android:angle="270"/>
    -->

    <stroke
        android:width="1dp"
        android:color="#A0000000" />

    <padding
        android:bottom="8dp"
        android:left="5dp"
        android:right="5dp"
        android:top="8dp" />

    <corners android:radius="5dp" />

</shape>

$ C $下list_item_ pressed.xml是:

code for list_item_pressed.xml is :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">

    <gradient
        android:centerColor="#E6E6E6"
        android:endColor="#CCCCCC"
        android:startColor="#FFFFFF" android:angle="270"/>
    <!--
         <gradient android:startColor="#FF66CFE6" android:centerColor="#FF207FB9" 
        android:endColor="#FF0060B8" android:angle="270"/>
    -->

    <stroke
        android:width="2dp"
        android:color="#80000000" />

    <padding
        android:bottom="8dp"
        android:left="5dp"
        android:right="5dp"
        android:top="8dp" />

    <corners android:radius="7dp" />

</shape>

$ C $下list_item_ pressed.xml:

code for list_item_pressed.xml :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">

    <gradient
        android:centerColor="#E6E6E6"
        android:endColor="#CCCCCC"
        android:startColor="#FFFFFF" android:angle="270"/>
    <!--
         <gradient android:startColor="#FF66CFE6" android:centerColor="#FF207FB9" 
        android:endColor="#FF0060B8" android:angle="270"/>
    -->

    <stroke
        android:width="2dp"
        android:color="#80000000" />

    <padding
        android:bottom="8dp"
        android:left="5dp"
        android:right="5dp"
        android:top="8dp" />

    <corners android:radius="7dp" />

</shape>

和list_gradient.xml

and list_gradient.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="@drawable/list_item_pressed" />

    <item android:state_focused="true"
          android:drawable="@drawable/list_item_selected" />

    <item android:drawable="@drawable/list_item_normal" />

</selector>

和我已经申请这种风格上的自定义列表项这样的:

and i have applied this style on custom listitem like :

<TextView
    .../>

<ImageView
   ... />

和main.xml中在我所lisview是:

and the main.xml in which i have lisview is :

<ListView
    android:id="@+id/List"
    style="@style/list_item_gradient"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:clickable="true" >
</ListView>

和我得到的输出,如下所示:

and i am getting output as shown below :

请帮我告诉我在做什么错了..

Please help me by telling what i am doing wrong..

谢谢 思鲁提

推荐答案

你知道抖动?检查此: http://android.amberfog.com/?p=247

Do you know about Dithering? Check this: http://android.amberfog.com/?p=247.

另外,请检查以下问题:

Also check these questions:

  1. <一个href="http://stackoverflow.com/questions/2936803/how-to-draw-a-smooth-dithered-gradient-on-a-canvas-in-android">How要绘制平滑/抖动在画布上梯度的Andr​​oid
  2. Android的观点抖动
  1. How to draw a smooth/dithered gradient on a canvas in Android
  2. Android view dithering

是的,我会建议你LitsView,在你只需要创建一个自定义行XML布局文件和应用的背景图像一次创建自定义适配器。

And yes, i would suggest to create custom adapter for your LitsView, in which you just have to create one custom row xml layout file and apply the background image for one time.

这篇关于应用样式到Android的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆