Отрегулируйте ширину кнопки в соответствии с возможностью рисования ImageButton

У меня два вопроса:

  1. В макете xml есть ImageButton, который является ресурсом. При наличии drawable-ldpi в xxhdpi разных размеров для этого imageButton ширина варьируется в зависимости от того, на каком устройстве запущено приложение. Внизу макета xml есть кнопка с 9 патчами, ширина которой должна совпадать с шириной кнопки drawable / imageButton.

  2. Как мне унаследовать динамику от 1. до второй кнопки с 9 патчами в другом макете xml?

Я попытался сделать RelativeLayout с wrap_content, который красиво обтекает все вокруг. Когда я устанавливаю buttonStart width на match_parent, он использует весь экран, а не ширину из UIWrapper. Любая помощь приветствуется. Спасибо!

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_activity_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:focusable="true"
    android:screenOrientation="portrait"
    tools:context=".MainActivity" >

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/UIWrapper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="62dp" >

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/imageWrapper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" >

            <ImageButton
                android:id="@+id/imageButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="false"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:background="?android:attr/selectableItemBackground"
                android:src="@drawable/my_gfx" />

            <TextView
                android:id="@+id/textViewTest"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_gravity="center_horizontal|top"
                android:clickable="false"
                android:shadowColor="@color/LightYellow"
                android:shadowDx="0.0"
                android:shadowDy="0.0"
                android:shadowRadius="24"
                android:text="Some Text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/DarkBlue"
                android:textSize="48dp" />
        </RelativeLayout>

        <TextView
            android:id="@+id/T0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/imageWrapper"
            android:layout_below="@+id/imageWrapper"
            android:layout_marginTop="10dp"
            android:text="@string/label"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/FloralWhite" />

        <RadioGroup
            android:id="@+id/T1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/T0"
            android:layout_below="@+id/T0" >

            <RadioButton
                android:id="@+id/radioButton0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:enabled="true"
                android:singleLine="true"
                android:text="@string/rd_0"
                android:textColor="@color/White" />

            <RadioButton
                android:id="@+id/radioButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:enabled="true"
                android:text="@string/rd1"
                android:textColor="@color/FloralWhite" />
        </RadioGroup>

        <Button
            android:id="@+id/buttonStart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="14dp"
            android:background="@drawable/default_button"
            android:text="@string/btn_start"
            android:textColor="@color/FloralWhite" />
    </RelativeLayout>
</RelativeLayout>

person Michael D.    schedule 13.01.2014    source источник
comment
Пожалуйста, дайте id нужных вам просмотров, ваш xml не очень понятен ...   -  person Seraphim's    schedule 14.01.2014
comment
Можете ли вы в общих чертах обрисовать то, что вы ожидаете?   -  person Seraphim's    schedule 14.01.2014


Ответы (1)


Первый

Чтобы получить такую ​​же ширину, используйте:

 android:id="@+id/buttonStart"
 android:layout_alignRight="@+id/..."
 android:layout_alignLeft="@+id/..."

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

  1. Я должен сказать: вы используете слишком много вложенных относительных макетов. Это непонятно и часто.
  2. вам не нужно повторять атрибут xmlns:android="http://schemas.android.com/apk/res/android" только один раз в первом элементе.
person Seraphim's    schedule 13.01.2014