选择不工作工作

2023-09-07 15:45:04 作者:ゆ撕念

我使用它的选择列表

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/arrow"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|left"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tvDescr"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical" >
        </TextView>
    </LinearLayout>

    <ImageView
        android:id="@+id/ivImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:maxHeight="20dp"
        android:minHeight="20dp" >
    </ImageView>

</LinearLayout>

和选择arrow.xml

and selector arrow.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item><shape>
            <gradient android:angle="90.0" android:endColor="#6495ED" android:startColor="#0000FF" android:type="linear" />

            <corners android:radius="5.0dp" />
        </shape></item>
    <item android:state_focused="true"><shape>
            <gradient android:angle="90.0" android:endColor="#BA55D3" android:startColor="#800080" android:type="linear" />

            <corners android:radius="5.0dp" />
        </shape></item>
    <item android:state_pressed="true"><shape>
            <gradient android:angle="90.0" android:endColor="#BA55D3" android:startColor="#800080" android:type="linear" />

            <corners android:radius="5.0dp" />
        </shape></item>

</selector>

结果是

- 不工作,但如果我删除(下文源),将工作

- does not work but if I remove (sources below) it will work

<item><shape>
                <gradient android:angle="90.0" android:endColor="#6495ED" android:startColor="#0000FF" android:type="linear" />

                <corners android:radius="5.0dp" />
            </shape></item>

但它并没有给我想要的结果,因为在你点击列表按钮的风格有改变 - 但这种情况不会发生。

but it does not give me the desired result, because after you click on the "list-button" style has to change - but this does not happen

我想提出:

1)之前pressing风格如图片1

1)Style before pressing as in the picture 1

2)当我preSS的按钮,按钮样式更改为2画面

2)After I press the button, the button style has to change as the 2 picture

3)继续下去的话,直到我点击另一个按钮

3)remain that way until I click on another button

推荐答案

一个选择是国家的名单抽拉,即它选择&LT;项目&GT; 取决于它被施加到视图的状态

a selector is a 'state-list-drawable', ie it 'selects' <items> depending upon the state of the view it is applied to.

一个StateListDrawable是使用在XML中定义的可绘制对象   几种不同的图像,以重新present相同的图形,这取决于   的对象的状态。例如,一个按钮控件可以在一个存在   几种不同的状态(pressed,突出重点,或niether)和使用   一个状态列表绘制,可以提供不同的背景图片   每个状态。

A StateListDrawable is a drawable object defined in XML that uses a several different images to represent the same graphic, depending on the state of the object. For example, a Button widget can exist in one of several different states (pressed, focused, or niether) and, using a state list drawable, you can provide a different background image for each state.

下面是语法,如文档:

<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:constantSize=["true" | "false"]
    android:dither=["true" | "false"]
    android:variablePadding=["true" | "false"] >
    <item
        android:drawable="@[package:]drawable/drawable_resource"
        android:state_pressed=["true" | "false"]
        android:state_focused=["true" | "false"]
        android:state_hovered=["true" | "false"]
        android:state_selected=["true" | "false"]
        android:state_checkable=["true" | "false"]
        android:state_checked=["true" | "false"]
        android:state_enabled=["true" | "false"]
        android:state_activated=["true" | "false"]
        android:state_window_focused=["true" | "false"] />
</selector>

注意,你可以在设置属性的&LT;项目&GT;

下面是一个典型的选择的一个例子。

here is an example of a typical selector..

<selector xmlns:android="http://schemas.android.com/apk/res/android" 
>
    <item
        android:state_focused="true" 
        android:state_pressed="false" 
android:drawable="@drawable/list_element_focused"   />
    <item
        android:state_focused="true" 
        android:state_pressed="true"
android:drawable="@drawable/list_element_focused_pressed"   />  
    <item
        android:state_focused="false" 
        android:state_pressed="true"
android:drawable="@drawable/list_element_pressed"   />  
    <item
android:drawable="@drawable/list_element_unfocused" />  
</selector>