2014-01-02 5 views
0

Я установил 4 линейных макета: 2 вертикальных, бок о бок и 2 горизонтальных, расположенных вертикально.
Это даст мне в общей сложности 3 вертикальных.LinearLayout не заполняет окно

Тогда конечная цель состоит в том, чтобы иметь один макет для нескольких размеров экрана.
Я установил вес всех 4 макетов на «1», чтобы заполнить равномерно.

Я попытался использовать android:layout_height="wrap_content", но он не заполняет весь фон.

Если я использую android:layout_height="fill_parent", макеты обрезаются.

Вот скриншот "wrap_content" enter image description here

Вот скриншот "fill_parent" enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ff606060" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".SimpleRGB_Main" > 

<LinearLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="0dp" 
     android:layout_marginTop="0dp" 
     android:layout_weight="1" 
     android:text="Scene 1" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button1" 
     android:layout_marginLeft="0dp" 
     android:layout_weight="1" 
     android:text="Scene 2" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button2" 
     android:layout_marginLeft="0dp" 
     android:layout_weight="1" 
     android:text="Scene 3" /> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button3" 
     android:layout_marginLeft="0dp" 
     android:layout_weight="1" 
     android:text="Scene 4" /> 

    <Button 
     android:id="@+id/button5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button4" 
     android:layout_marginLeft="0dp" 
     android:layout_weight="1" 
     android:text="Scene 5" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/relativeLayout2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/relativeLayout1" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/button6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="0dp" 
     android:layout_toRightOf="@+id/button1" 
     android:layout_weight="1" 
     android:text="Scene 6" /> 

    <Button 
     android:id="@+id/button7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button6" 
     android:layout_toRightOf="@+id/button2" 
     android:layout_weight="1" 
     android:text="Scene7" /> 

    <Button 
     android:id="@+id/button8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button7" 
     android:layout_toRightOf="@+id/button3" 
     android:layout_weight="1" 
     android:text="Scene8" /> 

    <Button 
     android:id="@+id/button9" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button8" 
     android:layout_toRightOf="@+id/button4" 
     android:layout_weight="1" 
     android:text="Scene9" /> 

    <Button 
     android:id="@+id/button10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/button9" 
     android:layout_toRightOf="@+id/button5" 
     android:layout_weight="1" 
     android:text="Scene10" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/relativeLayout3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/relativeLayout1" 
    android:layout_weight="1" 
    android:orientation="horizontal" > 

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

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



<LinearLayout 
    android:id="@+id/relativeLayout4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/relativeLayout3" 
    android:layout_weight="1" 
    android:orientation="horizontal" > 

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

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

Вот что я пытаюсь попытаться. Зеленый - это макеты, заполненные кнопками и виджетами.

enter image description here

ответ

1
<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ff606060" 
android:weightSum="6" 
android:layout_gravity="fill_horizontal|center_vertical" 
tools:context=".SimpleRGB_Main" > 

<TableRow 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:weightSum="2" 
    android:layout_weight="1"> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="0dp" 
    android:layout_marginTop="0dp" 
    android:layout_weight="1" 
    android:text="Scene 1" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button1" 
    android:layout_marginLeft="0dp" 
    android:layout_weight="1" 
    android:text="Scene 6" /> 
</TableRow> 
<TableRow 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:weightSum="2"> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button2" 
    android:layout_marginLeft="0dp" 
    android:layout_weight="1" 
    android:text="Scene 2" /> 

<Button 
    android:id="@+id/button4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button3" 
    android:layout_marginLeft="0dp" 
    android:layout_weight="1" 
    android:text="Scene 7" /> 
</TableRow> 
<TableRow 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:weightSum="2"> 

<Button 
    android:id="@+id/button5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button4" 
    android:layout_marginLeft="0dp" 
    android:layout_weight="1" 
    android:text="Scene 3" /> 
<Button 
    android:id="@+id/button6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="0dp" 
    android:layout_toRightOf="@+id/button1" 
    android:layout_weight="1" 
    android:text="Scene 8" /> 
</TableRow> 
<TableRow 
android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:weightSum="2"> 

<Button 
    android:id="@+id/button7" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button6" 
    android:layout_toRightOf="@+id/button2" 
    android:layout_weight="1" 
    android:text="Scene 4" /> 

<Button 
    android:id="@+id/button8" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button7" 
    android:layout_toRightOf="@+id/button3" 
    android:layout_weight="1" 
    android:text="Scene 9" /> 
</TableRow> 
    <TableRow 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:weightSum="2" 
    android:layout_weight="1"> 

<Button 
    android:id="@+id/button9" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button8" 
    android:layout_toRightOf="@+id/button4" 
    android:layout_weight="1" 
    android:text="Scene 5" /> 

<Button 
    android:id="@+id/button10" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button9" 
    android:layout_toRightOf="@+id/button5" 
    android:layout_weight="1" 
    android:text="Scene 10" /> 
</TableRow>  
    <TableRow 
    android:layout_width="wrap_content" 
    android:layout_weight="1"   
    android:layout_height="wrap_content" 
    android:weightSum="2"> 

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

<Button 
    android:id="@+id/button12" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="RECORD 1" /> 
</TableRow> 
<TableRow 
android:layout_width="wrap_content" 
android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:weightSum="2"> 

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

<Button 
    android:id="@+id/button12" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="PLAY 1" /> 
</TableRow> 
</TableLayout> 

графическое представление op

+0

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

+0

Ну, когда проблемы приходят к ширине и высоте устройств, я предлагаю подготовить 3-4 правила или несколько стандартов и перейти на разные xml. Я знаю его боль, но выбора нет ». – Sush

+0

Мне удалось настроить рабочий стол. Я отправлю результаты по завершении. спасибо за предложение. – Bobby

2

Ввод веса макета на детей RelativeLayout не работает. Весы работают только на LinearLayout (то есть, на детей линейного макета, а не на самой линейной компоновке). Попробуйте начать, сделав линейку корней линейной, а не RelativeLayout.

+0

Вес также работать на LinearLayouts, если они сами дети в LinearLayout;) –

+0

Да, именно поэтому я пытался передать. Я, вероятно, мог бы быть более ясным об этом –

+0

просто чтобы добавить мои 2 цента ...;) –

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