2013-08-05 4 views
0

Я создал виджет главного экрана, который использует представление списка и список элементов с относительным расположением, которое содержит два текстовых представления и изображение. Я хочу, чтобы при щелчке по элементу в представлении списка был выбран полный элемент, а не как теперь только текстовое представление или изображение, которое вы нажимаете. Как я могу это сделать? Я попробовал кое-что, но ничего не получилось. Bellow - это изображение, которое показывает, как оно выглядит сейчас.Полная строка, которую можно щелкнуть в главном экране виджета

Only row two is selected

Вот расположение виджета,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_marginBottom="0dp" 
android:orientation="vertical" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#80FFFFFF" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@android:id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:contentDescription="@string/widget_icon_description" 
     android:src="@drawable/ic_logo" /> 

    <TextView 
     android:id="@android:id/text1" 
     style="@android:style/TextAppearance.DeviceDefault.Large.Inverse" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:gravity="center_vertical" 
     android:text="@string/widget_list_heading" 
     android:textIsSelectable="false" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_blue_bright" 
    android:paddingBottom="2dp" > 
</LinearLayout> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="0dip" 
    android:layout_marginBottom="0dp" 
    android:layout_weight="1" 
    android:background="#f1f1f1" 
    android:listSelector="@android:color/holo_blue_bright" 
    android:paddingBottom="0dp" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_blue_bright" 
    android:paddingBottom="2dp" > 
</LinearLayout> 

А вот компоновки списка Просмотреть элемент

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="8dp" 
android:paddingRight="8dp" 
android:background="@drawable/list_selector_background_light" > 

<TextView 
    android:id="@android:id/text1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMediumInverse" 
    android:textIsSelectable="false" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@android:id/text2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@android:id/text1" 
    android:layout_below="@android:id/text1" 
    android:textAppearance="?android:attr/textAppearanceSmallInverse" 
    android:textIsSelectable="false" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right" 
    android:paddingRight="10dip" 
    android:paddingTop="8dip" > 

    <ImageView 
     android:id="@android:id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/expandable_heading_list_item_image_description" /> 
</LinearLayout> 

/Viktor

+0

Для уровня API 11+ вы можете использовать 'ListView'. – CommonsWare

+0

Я использую представление списка с настраиваемым элементом просмотра списка. Отлично работает, если я использую только android.R.layout.simple_list_item_1 или android.R.layout.simple_list_item_2, но мне нужен более продвинутый макет. – Viktor

ответ

0

ОК, нашел решение сейчас, через 13 минут после вопроса ... Просто добавлен «android: clickable = true» в относительный макет в элементе списка и добавлен «android: clickable = false» к подпунктам макета, удалили все ожидающие намерения из текстовых представлений и изображения и добавили их в относительный макет. Цель не работает, но это, надеюсь, то, что можно решить.

/Viktor

Смежные вопросы