1

Я пытаюсь создать меню с помощью FloatingActionButtons с сопровождающими TextViews слева от каждого пункта меню в качестве заголовка. У меня возникают трудности с созданием макета, как хотелось бы. Я бы хотел, чтобы все FloatingActionButtons справа, и TextView рядом с каждым. Это мой код прямо сейчас:Android RelativeLayout view clumping up

<LinearLayout 
    android:id="@+id/fab_menu_container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true"> 

    <RelativeLayout 
     android:id="@+id/fab_menu" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:visibility="invisible"> 

     <TextView 
      android:id="@+id/txt_button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button 1" 
      android:layout_margin="8dp"/> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/txt_button1"/> 

     <TextView 
      android:id="@+id/txt_button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button 2" 
      android:layout_below="@id/txt_button1"/> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/txt_button2" 
      android:layout_below="@id/button1"/> 

     <TextView 
      android:id="@+id/txt_button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button 3" 
      android:layout_below="@id/txt_button2"/> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/txt_button3" 
      android:layout_below="@id/button2"/> 
    </RelativeLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:clickable="true" 
     android:onClick="generateMenu"/> 
</LinearLayout> 

ответ

0

Я думаю, что это то, что вы ищете

<LinearLayout 
    android:id="@+id/fab_menu_container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:gravity="right" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/fab_menu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:id="@+id/fab1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/txt_button1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Button 1" /> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/button1" 
       android:layout_margin="16dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 


     <LinearLayout 
      android:id="@+id/fab2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/txt_button2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Button 2" /> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/button2" 
       android:layout_margin="16dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/fab3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/txt_button3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Button 3" /> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/button3" 
       android:layout_margin="16dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 
    </LinearLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:clickable="true" 
     android:onClick="generateMenu" /> 

</LinearLayout> 

Результат

enter image description here

Но еще я рекомендую вам использовать FloatingActionButton библиотека. это просто как чай;)

Счастливый кодирования ..

+1

Да! Это именно то, что я ищу: D Библиотека еще лучше! – Jesse

+0

рад помочь .. –

0

В соответствии с его документацией кнопки плавающего действия используются для специального типа продвигаемого действия. Избегайте использования кнопок плавающего действия для незначительных и деструктивных действий. Только одна плавающая кнопка действия рекомендуется для каждого экрана, чтобы увеличить ее известность. Он должен представлять только наиболее распространенное действие.

Читать эту ссылку https://material.google.com/components/buttons-floating-action-button.html#buttons-floating-action-button-floating-action-button

для лучшего FAB использования

+0

Я использую его для меню, так что на первый взгляд было бы только один плавучий действие кнопки на экране. После нажатия этой кнопки другие кнопки становятся видимыми, и вы можете перемещаться оттуда. Подобно тому, как это имеет приложение Facebook Messenger. – Jesse

0

Вы хотите?. Легко справитесь с LinearLayout, почему бы вам не использовать его.

enter image description here

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

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

      <TextView 
       android:id="@+id/txt_button1" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:gravity="center_vertical" 
       android:layout_margin="8dp" 
       android:layout_weight="0.8" 
       android:text="Button 1" /> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/txt_button1" 
       android:gravity="right" /> 

     </LinearLayout> 


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

      <TextView 
       android:id="@+id/txt_button2" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="8dp" 
       android:gravity="center_vertical" 
       android:layout_weight="0.8" 
       android:text="Button 1" /> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/button2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/txt_button1" /> 

     </LinearLayout> 


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

      <TextView 
       android:id="@+id/txt_button3" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_margin="8dp" 
       android:layout_weight="0.8" 
       android:gravity="center_vertical" 
       android:text="Button 1" /> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/button3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/txt_button1" /> 

     </LinearLayout> 


     <android.support.design.widget.FloatingActionButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="16dp" 
      android:layout_gravity="center_horizontal" 
      android:clickable="true" 
      android:onClick="generateMenu" /> </LinearLayout> 
0

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

Если вы хотите сделать что-то вроде этого,

enter image description here

затем посмотреть this question его о том же, что вы могли бы пытаться достигать.

см. this library и this library тоже.

Довольно хороший учебник объяснить хороший способ сделать это является here

Смежные вопросы