Я новачок у розробці Android, і у мене виникає питання про встановлення ваги в лінійному макеті.
Я намагаюся створити рядок із двома користувацькими кнопками та спеціальним текстом редагування. Текст редагування повинен займати стільки місця, скільки його вміст, а дві кнопки повинні розширюватися горизонтально, щоб заповнити решту вільного місця в рядку. Подобається це...
| [#Button++#] [#Button--#] [et] |
Після кількох спроб це найближче, що я можу досягти того, що хочу, хоча це здається надто складним.
| [Button] [Button] [###ET###] |
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:layout_weight="1"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<RelativeLayout
android:id="@+id/btn_plus_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/btn_plus"
android:background="@drawable/btn"
android:layout_centerInParent="true"
></ImageButton>
<TextView
android:textColor="#FAFAF4"
android:id="@+id/tv_dice_plus"
android:text="@string/tv_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
></TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<RelativeLayout
android:id="@+id/btn_minus_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/btn_minus"
android:background="@drawable/btn"
android:layout_centerInParent="true"
></ImageButton>
<TextView
android:textColor="#FAFAF4"
android:id="@+id/btn_minus"
android:text="@string/tv_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
></TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<EditText
android:textColor="#FAFAF4"
android:text="@string/et_output"
android:id="@+id/et_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:selectAllOnFocus="true"
android:minWidth="50sp"
android:maxWidth="50sp"
android:background="@drawable/tv_black_background3"
android:textColorHighlight="#c30505"
></EditText>
</LinearLayout>
</LinearLayout>
Як я розумію, установка [android: layout_weight = "2"] для лінійних макетів, що утримують кнопки, повинна зайняти більше місця, ніж редагування тексту, але для мене це робить навпаки, роблячи їх обох вдвічі меншими.
| [Btn] [Btn] [#####et#####] |
Я спробував стільки різних комбінацій, що навіть не пам’ятаю їх, і жодна з них не спрацювала.