Как обеспечить равные места для этого FAB в XML? - PullRequest
0 голосов
/ 01 ноября 2019

Пожалуйста, найдите изображение

enter image description here

Вот мой макет XML: я пишу этот код для своего приложения

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
        android:layout_height="match_parent"
    tools:context=".FullScreenImageActivity">

        <com.github.chrisbanes.photoview.PhotoView
            android:id="@+id/image11"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:src="@drawable/navimage" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="4dp"
            android:orientation="horizontal"
            android:weightSum="2">

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/download_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/download"
                app:backgroundTint="@android:color/white" />

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/download_sbtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/download"
                app:backgroundTint="@android:color/white" />
     </LinearLayout>
    </RelativeLayout>

Может ли кто-нибудь указать мне, почему это не работает? Любые предложения будут полезны

Ответы [ 3 ]

1 голос
/ 01 ноября 2019

Это потому, что FloatingActionButton может иметь только фиксированный размер.

Вы можете добавить пробел между ними.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="2">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="5dp"
android:paddingEnd="5dp">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/download_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/download"
app:backgroundTint="@android:color/white" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="5dp"
android:paddingEnd="5dp">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/download_btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/download"
app:backgroundTint="@android:color/white" />

</LinearLayout>
</LinearLayout>
1 голос
/ 01 ноября 2019

Всегда было бы лучше узнать из официальной документации. Вот так:

WeightSum документация:

Определяет максимальную сумму веса. Если не указано, сумма вычисляется путем добавления layout_weight для всех дочерних элементов. Это может использоваться, например, чтобы дать одному дочернему элементу 50% от общего доступного пространства, задав ему layout_weight 0,5 и установив weightSum равным 1,0.

Может быть значением с плавающей запятой, таким как «1,2».

Вес макета Документация:

Указывает, сколько дополнительного пространства в LinearLayout выделено представлению, связанному с этими LayoutParams. Укажите 0, если вид не должен быть растянут. В противном случае дополнительные пиксели будут пропорционально распределены среди всех представлений, вес которых больше 0.

Может быть значением с плавающей запятой, например, "1.2".

0 голосов
/ 01 ноября 2019

Вы должны использовать что-то другое.

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:gravity="center_horizontal"
      >

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        .../>

  </LinearLayout>

  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:gravity="center_horizontal"
      >
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        .../>
  </LinearLayout>

</LinearLayout>

enter image description here enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...