选择不工作的布局和图像视图视图、布局、图像、工作

2023-09-04 10:16:45 作者:名字什么都是浮云

我想用选择的布局和图像view..But它不是为我工作。 当我改变形象,以ImageButton的或按钮,它工作正常。任何帮助将大大AP preciated ..在此先感谢.. 这里是我用了XMLS ..

 < XML版本=1.0编码=UTF-8&GT?;
<选择
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <! - 当选择,使用灰色 - >
    <项目
        机器人:STATE_ pressed =真
        机器人:可绘制=@可绘制/ BG
        />
    <! - <项目

        机器人:可绘制=@可绘制/ BG
        机器人:state_focused =真/>
     如果未被选中,用白 - >

    <项目
        机器人:可绘制=@可绘制/ bg_01/>
< /选择器>

 - >布局的xml:
< XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:方向=垂直
    机器人:layout_height =FILL_PARENT>
    <的ImageButton
        机器人:layout_width =100dp
        机器人:layout_height =50dp
        机器人:文本=版面计
        机器人:文字颜色=#000000
        机器人:TEXTSTYLE =黑体
        机器人:paddingTop =10dp
        机器人:SRC =@可绘制/ testselector
        机器人:layout_gravity =center_horizo​​ntal/>
    < / LinearLayout中>
 

解决方案

我就遇到了这个问题,刚才。你必须给的LinearLayout设置为可点击。你可以做到这一点的XML与

 机器人:可点击=真
 

或与

code

  yourLinearLayout.setClickable(真正的);
 
CAD三维图俯视图快捷键

干杯!

I want to use selector for a layout and image view..But it is not working for me. When I changed image view to imagebutton or button, it works fine. Any help will be greatly appreciated.. Thanks in advance.. here is the xmls I used..

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/bg" 
        />
    <!--<item

        android:drawable="@drawable/bg" 
        android:state_focused="true"/>
     When not selected, use white-->

    <item
        android:drawable="@drawable/bg_01" />
</selector> 

-> The layout xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="fill_parent">
    <ImageButton
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:text="layout tester"
        android:textColor="#000000"
        android:textStyle="bold"
        android:paddingTop="10dp"
        android:src="@drawable/testselector"
        android:layout_gravity="center_horizontal" />
    </LinearLayout>

解决方案

I ran into this problem just now. You'll have to set the LinearLayout to clickable. You can either do this in the XML with

android:clickable="true"

Or in code with

yourLinearLayout.setClickable(true);

Cheers!