Как разделить линейный макет на четыре равные части? - PullRequest
0 голосов
/ 02 августа 2020

Я хочу дать Textview 3/4 линейного макета и viewbutton view 1/4. Но это работает не так, как задумано, но если я сделаю четыре кнопки, он разделит их поровну.

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">
    <TextView
        android:background="@color/dark"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:id="@+id/txtresult"
        android:text=""
        android:textColor="@color/colorPrimary"
        android:textSize="50sp"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/del"
        android:text="@string/del"
        android:autoSizeTextType="uniform"
        style="@style/Widget.MaterialComponents.Button"
        android:textColor="#fff"
        android:layout_weight="1"
        android:src="@drawable/ic_action_name"
        android:scaleType="fitCenter" />

    </LinearLayout>

Ответы [ 2 ]

0 голосов
/ 06 августа 2020

сначала Удалите android:layout_weight="1" из LinearLayout. затем установите android:layout_width="0dp" для TextView и ImageButton. а затем установите android:layout_weight="0.75" для TextView и установите android:layout_weight="0.25" для ImageButton.

вот так:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
<TextView
    android:background="@color/dark"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.75"
    android:id="@+id/txtresult"
    android:text=""
    android:textColor="@color/colorPrimary"
    android:textSize="50sp"/>
<ImageButton
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:id="@+id/del"
    android:text="@string/del"
    android:autoSizeTextType="uniform"
    style="@style/Widget.MaterialComponents.Button"
    android:textColor="#fff"
    android:layout_weight="0.25"
    android:src="@drawable/ic_action_name"
    android:scaleType="fitCenter" />

</LinearLayout>
0 голосов
/ 06 августа 2020

Удалите "layout_weight" из "LinearLayout". Отметьте его работу для меня.

Вот код:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:id="@+id/txtresult"
        android:text=""
        android:textColor="@color/colorPrimary"
        android:textSize="50sp"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/del"
        android:autoSizeTextType="uniform"
        android:textColor="#fff"
        android:layout_weight="1"
        android:scaleType="fitCenter" />
</LinearLayout>
...