Я хочу отображать кнопки в нижней части экрана, а кнопки находятся внутри linearLayout4, может кто-нибудь, пожалуйста, скажите мне об этом, я сейчас расстроен

#android #android-layout

#Android #android-макет

Вопрос:

Проблема с последним линейным макетом, содержащим кнопки, я хочу отобразить свой последний линейный макет, то есть id-linearlayout4, в нижней части экрана, чтобы мои кнопки были внизу…

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

     <LinearLayout android:orientation="vertical" android:id="@ id/linearLayout1"                           android:layout_width="match_parent" android:layout_height="60dip"></LinearLayout>

         <LinearLayout android:layout_width="match_parent" android:id="@ id/linearLayout5"               android:layout_height="wrap_content">

      <TextView android:layout_height="wrap_content" 
android:layout_width="wrap_content"       
 android:layout_alignParentTop="true" 
android:layout_toRightOf="@ id/textView2"              
 android:layout_marginLeft="19dp"
 android:id="@ id/quesname" 
android:textSize="20dip"     
android:textColor="#000000"></TextView>
       </LinearLayout>

      <LinearLayout android:id="@ id/linearLayout3" 
android:orientation="vertical"       
android:layout_height="wrap_content" 
android:layout_width="match_parent">
         <ScrollView android:id="@ id/ScrollView01"
          android:layout_width="fill_parent"
android:layout_height="wrap_content">
        <LinearLayout android:id="@ id/linearLayout2" 
android:orientation="vertical"           
  android:layout_height="wrap_content" 
android:layout_width="match_parent">
          <LinearLayout android:id="@ id/optionslayout" 
android:orientation="vertical"        
 android:layout_height="wrap_content" 
android:layout_width="match_parent">
           </LinearLayout>


        </LinearLayout>

        </ScrollView>
        <LinearLayout android:layout_height="wrap_content" android:id="@ id/linearLayout4"          android:layout_width="match_parent" android:gravity="bottom">
         <Button android:id="@ id/prev" android:layout_width="100dip"         android:text="Previous" android:layout_height="wrap_content"></Button>
           <Button android:id="@ id/next" android:layout_marginLeft="120dip"       android:layout_width="100dip" android:text="Next" android:layout_height="wrap_content">        </Button>
       </LinearLayout>
         </LinearLayout>
          </LinearLayout>
  

Комментарии:

1. если вы отформатируете свой код таким образом, никто не будет тратить свое время на его чтение

Ответ №1:

вы можете вставить

 <View android:layout_height="0dp" android:layout_width="0dp" android:layout_weight="1"/>
  

прямо перед вашими кнопками.

Или используйте относительный макет с alignParentBottom =»true»

Ответ №2:

Вам нужен RelativeLayout вместо LinearLayout в качестве родительского; затем просто перетащите кнопки в layout-GUI вниз, и они должны оставаться там. Когда я дома, я могу опубликовать «реальный» пример кода.

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout …>
<!-- your posted code -->
  

Перетаскивание родительского макета кнопки вниз приведет к:

 alignParentBottom="true"