微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linearLayout等布局添加动态背景运用xml注意加上clickable

</pre><p><pre name="code" class="html">

博主这些天在写一个app社交软件,开发过程中奇葩问题也是各种乱入,这个也算是其中之一,主要以前不用layout布局做按钮类,所以也不会做它的背景。话不多说,上代码

这是布局文件

<pre name="code" class="html"><LinearLayout
        android:id="@+id/ll_photo_local_get"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:background="@drawable/tv2_selector"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="现在拍摄"
            android:textColor="@color/deepgrey"
            android:textSize="18sp" />
    </LinearLayout>


 
 

这是tv1_selector选择器:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="false" android:state_focused="false" android:drawable="@color/white"></item>
    <item android:state_focused="true" android:drawable="@color/lightgray"></item>
    <item android:state_pressed="true" android:drawable="@color/lightgray"></item>

</selector>

然后怎么也出不来这个效果


本来感觉根本不会出问题的,后来在网上查了才知道layout都有一个clickable属性,否则点击是无效的

更改布局文件

<LinearLayout
    android:id="@+id/ll_photo_local_get"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:clickable="true"          //这里为新增
    android:background="@drawable/tv2_selector"
    android:orientation="vertical" >


    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="10dp"
      android:text="现在拍摄"
      android:textColor="@color/deepgrey"
      android:textSize="18sp" />
  </LinearLayout>
这样就有该有的效果了。希望能帮助一些还会碰上这个问题的人吧!~

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类