Android的可点击的布局 [英] Android clickable layout

查看:142
本文介绍了Android的可点击的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我已经设置为true是clikable +焦点线性布局,但问题是不存在焦点点击时显示。我怎样才能显示焦点。

这是我的code

 <的LinearLayout
  机器人:ID =@ + ID / linear_tv_layout
  机器人:方向=横向
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT
  机器人:layout_weight =1
  机器人:可点击=真
  机器人:可聚焦=真
  机器人:paddingBottom会=7px的>
 

解决方案

我想你需要设置为背景,点击视图(布局)一个的state列表绘制,这对您可以指定不同的可绘制不同的国家或国家组合的绘制资源,有一个选择,一个是pression等。此外,布局的状态传播到其所有的孩子。


澄清 - 这是从previously链接文档的例子:

RES /绘制/ button.xml:(它的状态列表绘制)

 < XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目的android:STATE_ pressed =真
          机器人:可绘制=@可绘制/ button_ pressed/> <  - !pressed  - >
    <项目安卓state_focused =真
          机器人:可绘制=@可绘制/ button_focused/> <! - 集中 - >
    <项目机器人:可绘制=@可绘制/ button_normal/> <! - 默认 - >
< /选择器>
 

button_ pressed button_focused button_normal 是正常的可绘制重新presenting按钮,在这些国家,可能巴布亚新几内亚(所以pressed可以镶嵌,重点以橙色高亮显示)。

如果你设置这个资源为背景,以你的线性布局按钮:

 <的LinearLayout
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =WRAP_CONTENT
    机器人:背景=@可绘制/按钮>
    ...
< / LinearLayout中>
 

现在的工作重点将自动设置它的背景图像布局@绘制/ button_focused ,等等。

当然,所有的使用必须已经资源 RES /绘制/ ,以及 button.xml

I've got a linear layout that i have set true to be clikable + focus, But the problem is there is no focus displayed when clicked. How can i get the focus to be displayed.

Heres my code

<LinearLayout
  android:id="@+id/linear_tv_layout"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight="1"
  android:clickable="true"
  android:focusable="true"
  android:paddingBottom="7px">

解决方案

I think you need to set as background for the clickable view (the layout) a state list drawable , it's a drawable resource for which you can specify different drawables for different states or combinations of states, there's one for selection, one for pression and so on. Also, the state of a layout propagates to all its children.


CLARIFICATIONS - this is the example from the previously linked docs:

res/drawable/button.xml : (it's the state list drawable)

<?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/button_pressed" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/button_focused" /> <!-- focused -->
    <item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>

button_pressed, button_focused and button_normal are normal drawables representing the button in those states, probably png's (so pressed could be inset, focused highlighted in orange).

if you set this resource as background to your "linear layout button":

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/button">
    ...
</LinearLayout>

now focusing the layout will automatically set its background image to @drawable/button_focused, and so on.

of course, all the drawables you use must already be resources in res/drawable/, together with button.xml.

这篇关于Android的可点击的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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