Справка по разметке иконок - PullRequest
1 голос
/ 12 мая 2011

Я пытаюсь повторить компоновку Apple своих значков приложений.У меня проблемы с использованием <merge> и <include>, так как при запуске приложения оно не отображается.

Icon

Вот часть слияния:

<Button android:id="@+id/deleteContact"
        android:text="X"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

<TextView android:id="@+id/personName"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="bottom|right"
          android:layout_gravity="bottom|right"
          android:textSize="20sp"
          android:text="asdfasdf"/>

<ImageView android:id="@+id/personImage"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:src="@drawable/icon"/>       

</merge>

Включение здесь:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content">

<include layout="@layout/icon"/>

 </LinearLayout>

Я помещаю их в сетку:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
              android:id="@+id/contactsGrid"
              android:layout_width="fill_parent"
              android:layout_weight="1"
              android:layout_height="fill_parent"
              android:numColumns="3"
              android:horizontalSpacing="3dip"
              android:verticalSpacing="3dip" />

Нам удалось объединить изображениеи текст до сих пор с использованием относительных слоев, однако, когда мы добавляем кнопку удаления, сам значок больше не может быть нажат.

1 Ответ

0 голосов
/ 12 мая 2011

Похоже, вы усложняете вещи больше, чем они, возможно, должны быть. Попробуйте использовать RelativeLayout в качестве родительского представления для кнопки, текста и изображения. Например, взгляните на следующее:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/personImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<TextView android:id="@+id/personName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/personImage"
    android:layout_alignRight="@id/personImage"/>
<Button android:id="@+id/deleteContact"
    android:text="X"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@id/personImage"
    android:layout_alignLeft="@id/personImage"/>
</RelativeLayout>

На самом деле вы должны иметь возможность просто использовать это в GridView. Вы можете заменить кнопку на кнопку ImageButton, которая использует фактическое изображение.

...