如何从Android的大号preVIEW设计让Android列表视图设计 [英] How to make Android List View Design from Android L Preview Design

查看:175
本文介绍了如何从Android的大号preVIEW设计让Android列表视图设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让Android大号preVIEW影像风格列表项。 这是我的code,这些类似的设计。

//绘制对象/ list_item_bg.xml

 < XML版本=1.0编码=UTF-8&GT?;

     <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
          <项目>
                <形状
                 机器人:形状=矩形>
                  [固体机器人:颜色=#E6E6E6/>
                < /形状>
          < /项目>
          <项目安卓底=1DP>
              <形状
                    机器人:形状=矩形>
                   [固体机器人:颜色=#FAFAFA/>
              < /形状>
          < /项目>
      < /层列表>
 

//绘制对象/ list_icon_bg

 <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:形状=椭圆形>
    [固体机器人:颜色=@色/ list_grey_bg/>
< /形状>
 

//布局/ list_item可

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =72dp>

    < ImageView的
        机器人:ID =@ + ID / list_icon
        机器人:layout_width =40dp
        机器人:layout_height =40dp
        机器人:layout_margin =16DP
        机器人:SRC =@可绘制/拇指
        机器人:背景=@可绘制/ list_icon_bg/>

    <的LinearLayout
        机器人:方向=垂直
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:重力=center_vertical
        机器人:背景=@可绘制/ list_item_bg
        机器人:layout_toRightOf =@ + ID / list_icon
        机器人:layout_alignParentRight =真
        机器人:layout_alignParentEnd =真
        机器人:layout_alignParentTop =真
        机器人:layout_alignParentBottom =真正的>

        <的TextView
            机器人:ID =@ + /标记
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字颜色=@色/ primary_text
            机器人:paddingRight =16DP
            机器人:文本=示例文本/>

    < / LinearLayout中>

< / RelativeLayout的>
 

但我已经为列表项选择状态的问题。列表项选择状态的背景颜色是唯一的图标领域的工作。选定的国家的列表项的背景颜色是不工作的LinearLayout区域。我该如何解决。

解决方案

  activity_main:
============


< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =72dp
机器人:背景=@可绘制/ list_icon_bg>

    < ImageView的
        机器人:ID =@ + ID / list_icon
        机器人:layout_width =40dp
        机器人:layout_height =40dp
        机器人:layout_margin =16DP
        机器人:SRC =@可绘制/拇指
        />

    <的LinearLayout
        机器人:方向=垂直
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:重力=center_vertical
        机器人:背景=@可绘制/ list_item_bg
        机器人:layout_toRightOf =@ + ID / list_icon
        机器人:layout_alignParentRight =真
        机器人:layout_alignParentEnd =真
        机器人:layout_alignParentTop =真
        机器人:layout_alignParentBottom =真正的>

        <的TextView
            机器人:ID =@ + /标记
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字颜色=@色/ primary_text
            机器人:paddingRight =16DP
            机器人:文本=示例文本/>

    < / LinearLayout中>

< / RelativeLayout的>
 

I make Android L preview image style list item. This is my code for these similar design.

// Drawable/list_item_bg.xml

<?xml version="1.0" encoding="utf-8"?>

     <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
          <item>
                <shape
                 android:shape="rectangle">
                  <solid android:color="#E6E6E6" />
                </shape>
          </item>
          <item android:bottom="1dp">
              <shape
                    android:shape="rectangle">
                   <solid android:color="#FAFAFA" />
              </shape>
          </item>
      </layer-list>

//Drawable/list_icon_bg

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@color/list_grey_bg" />
</shape>

// Layout/list_item

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp">

    <ImageView
        android:id="@+id/list_icon"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_margin="16dp"
        android:src="@drawable/thumb"
        android:background="@drawable/list_icon_bg"/>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:background="@drawable/list_item_bg"
        android:layout_toRightOf="@+id/list_icon"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true">

        <TextView
            android:id="@+id/label"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/primary_text"
            android:paddingRight="16dp"
            android:text="Sample Text" />

    </LinearLayout>

</RelativeLayout>

But i have problem for list item selected state. Background Color of list item selected state is work on icon area only. Selected state's list item background color is not working on LinearLayout area. How can i fix.

解决方案

activity_main:
============


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="@drawable/list_icon_bg">

    <ImageView
        android:id="@+id/list_icon"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_margin="16dp"
        android:src="@drawable/thumb"
        />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:background="@drawable/list_item_bg"
        android:layout_toRightOf="@+id/list_icon"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true">

        <TextView
            android:id="@+id/label"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/primary_text"
            android:paddingRight="16dp"
            android:text="Sample Text" />

    </LinearLayout>

</RelativeLayout>

这篇关于如何从Android的大号preVIEW设计让Android列表视图设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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