shape等特殊xml

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> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值