【问题标题】:How to remove focus from button in android?如何从android中的按钮中删除焦点?
【发布时间】:2012-12-29 04:37:08
【问题描述】:

我有这样的布局

<RelativeLayout
            android:id="@+id/layout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="buttonClick" >

            <ImageView
                android:id="@+id/img1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:background="@drawable/imageView_bg"
                android:focusable="false"
                android:focusableInTouchMode="false" />

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="18dip"
                android:background="@drawable/button_bg"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:gravity="left|center_vertical"
                android:paddingLeft="25dip"
                android:text="TEXT"
                android:textColor="#ffffff"
                android:textSize="20dip" />
        </RelativeLayout>

button_bg.xml

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

</selector>

imageView_bg.xml

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

    </selector>

我想整体单击视图。按钮和图像视图都已按下图像。单击RelativeLayout 时,按钮和图像视图被按下。 这怎么可能?使用上面的布局,按钮和图像视图分别按下时会显示按下的图像。

提前致谢

【问题讨论】:

    标签: android android-layout background


    【解决方案1】:

    你可以这样做,

    相对布局点击执行的ON事件,

    button.perfomClick()
    imagebutton.perfomClick()
    

    希望对你有帮助..

    【讨论】:

    • 它不适合我。ImageView 和 Button 分别单击它们时会显示按下的图像。
    猜你喜欢
    • 2011-02-19
    • 2021-12-25
    • 2011-03-03
    • 1970-01-01
    • 2012-11-05
    • 2011-01-27
    • 2011-04-03
    • 1970-01-01
    • 2021-06-04
    相关资源
    最近更新 更多