2014-01-07 6 views
0

enter image description hereAndroid Linear Layout Кнопка выравнивания

Я хочу разработать Linear Layout нечто подобное. Кнопка 1 должна приобрести 50% пространства макета, но она не должна растягиваться. Я укажу ширину кнопки 1. Аналогично, кнопки 2 и кнопка 3 должны получить оставшиеся 50% макета, и я хочу указать прописку слева для кнопки 2 из центра, а справа - для кнопки 3 с правого края макета.

Как я могу это сделать?

Мой текущий код:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 
    <Button 
     android:layout_height="30dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="0.5" 
     android:text="Button1" 
     /> 
    <Button 
android:layout_height="30dp" 
android:layout_width="fill_parent" 
android:layout_weight="0.75" 
android:text="Button2" 
    /> 

    <Button 
android:layout_height="30dp" 
android:layout_width="fill_parent" 
android:layout_weight="0.75" 
android:text="Button3" 
    /> 
</LinearLayout> 

ответ

1

Вместо того, взвешиванию кнопки, вы можете создать два макета и поместить их по 1 на каждый, чтобы они заполнили 50% экрана каждый .., а затем вы можете манипулировать размером кнопки внутри каждого макета, как хотите.

<?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="horizontal" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" > 

     <Button 
      android:id="@+id/button2" 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

    </LinearLayout> 

</LinearLayout> 
+0

Это то, что я искал. Проблема решена. Спасибо. – Ravindra

0

Вы можете сделать это с помощью LinearLayout с 3 кнопками, просто добавьте нужное вес кнопок, что-то вроде этого:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    <Button 
     android:id="@+id/Button01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" android:layout_weight="4"/> 

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

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

</LinearLayout> 
Смежные вопросы