1.用 shape 作为背景

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f0600000"/>
<stroke android:width="3dp" color="#ffff8080"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>

一定要注意solid android:color="#f0600000" 是背景色 要用8位 最好不要完全透明不然没有效果啊 这句话本来就不是背景色 的意思

2.类似多选的效果:
(1)

listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

listView.setItemsCanFocus(false);
(2) define list item
CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:background="@drawable/txt_view_bg"/>
(3) define drawable txt_view_bg.xml <item android:drawable="@drawable/selected" android:state_checked="true" /> <item android:drawable="@drawable/not_selected" />

3.
<LinearLayout android:layout_width ="100dp" android:layout_height="wrap_content" />
LinearLayour ll = new LinearLayout(this);parentView.addView(ll, new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT));

4. 当设置 TextView setEnabled(false)时 背景颜色你如果用#ffff之类的话可能不会显示 你最好使用 android:textColor这个属性而不是使用color。
<TextView android:text="whatever text you want" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/example" />

res/color/example.xml):

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false" android:color="@color/disabled_color" /> <item android:color="@color/normal_color"/></selector>

http://developer.android.com/intl/zh-CN/reference/android/content/res/ColorStateList.html

5.
http://android.amberfog.com/?p=9
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#FFF8F8F8" />
</shape>
</item>
<item android:top="23px">
<shape>
<solid android:color="#FFE7E7E8" />
</shape>
</item>
</layer-list>
You can simple combine several drawables into one using <layer-list> tag.
note: Unfortenately you cannot resize drawables in layer-list. You can only move it.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/shape_below"/> <item android:top="10px" android:right="10px" android:drawable="@drawable/shape_cover"/></layer-list>


include
You can put similar layout elements into separate XML and use <include> tag to use it.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="64dip"
android:gravity="center_vertical"
android:ignoreGravity="@+id/icon">

<include layout="@layout/track_list_item_common" />;

</RelativeLayout>

track_list_item_common.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<ImageView android:id="@+id/icon"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="4dip"
android:layout_width="60px"
android:layout_height="60px"/>
...
</merge>

更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. android中Dialog 的使用例子
  6. Android(安卓)TabWidget/TabHost的使用
  7. android Studio中关于Gradle的使用注解
  8. drawable中的layer-list使用
  9. Android(安卓)拖拽

随机推荐

  1. RelativeLayout
  2. ListView中添加Button后,Button的点击事件
  3. Android(安卓)5.0 API 的变化——开发人
  4. Android(安卓)微信/支付宝 h5调原生支付
  5. ExpandableListView设置选中child的背景
  6. 安卓开发
  7. 怎么给Android(安卓)控件添加边框(样式)?
  8. FregServer进程,发送BC_TRANSACTION,唤醒Se
  9. Android命令行手动编译打包详解
  10. RecyclerView初级使用