2016-05-20 5 views
0

У меня есть два LinearLayout внутри RelativeLayout. Я просто хочу сделать это LinearLayout внутри одного LinearLayout, чтобы мой дочерний элемент управления отображался внутри 1 LinearLayout. так что я могу создать группу этого LinearLayout и отобразить с цветом фона android:background="@drawable/my_custom_background, чтобы все дочерние элементы управления подключались к нему.Объедините два LinearLayouts в один LinearLayout

см ниже снимок экрана enter image description here код

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#0B95BA" 
    android:minWidth="25px" 
    android:minHeight="25px"> 
    <LinearLayout 
     android:id="@+id/linearLayoutCont" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="5dp"> 
     <TextView 
      android:id="@+id/txtViewCont" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="Contact Billing" 
      android:gravity="center" 
      android:textSize="25sp" 
      android:textColor="#FFFFFF" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/linearLayoutContBillingCall" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@id/linearLayoutCont" 
     android:layout_marginTop="5dp"> 
     <Button 
      android:text="Call" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="15sp" 
      android:textColor="#FFFFFF" 
      android:layout_gravity="right" 
      android:background="@drawable/ButtonStyle" 
      android:id="@+id/btnContCall" 
      android:drawableLeft="@drawable/PhoneCall" /> 
     <Button 
      android:text="Email" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="15sp" 
      android:textColor="#FFFFFF" 
      android:layout_gravity="right" 
      android:background="@drawable/ButtonStyle" 
      android:id="@+id/btnEmail" 
      android:drawableLeft="@drawable/Email" /> 
    </LinearLayout> 
</RelativeLayout> 

и о/р должна быть выше ПОС, как Контакты в центре и две кнопки (вызова и электронная почта) ниже контактной же углу , также я хочу спросить, как создать пространство между этими двумя кнопками.

+0

Вы пытаетесь объединить 2 LinearLayouts с различными ориентациями - их невозможно объединить в один. Просто используйте RelativeLayout, чтобы расположить элементы управления без каких-либо LinearLayouts. – adelphus

+0

@adelphus Я попробовал, но детское управление не показано на нем. – Pritish

+0

@adelphus я пробовал android: id = "@ + id/linearLayoutCont" он показывает мне дочерний контроль Контакт, звонок, электронная почта в одной строке, то есть в одной строке Я хочу, чтобы она была на COntact выше, а также кнопку Call and Email ниже. – Pritish

ответ

2

Вы должны использовать только один Linear Layout вместо двух. Ваш Text View является дочерним вашим Relative Layout. Я применил некоторые модификации к вашему Layout.

См. Это.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#0B95BA"> 


    <TextView 
     android:id="@+id/txtViewCont" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="Contact Billing" 
     android:textColor="#FFFFFF" 
     android:textSize="25sp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/txtViewCont" 
     android:orientation="horizontal" 
     android:weightSum="2"> 


     <Button 
      android:id="@+id/btnContCall" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:drawableLeft="@mipmap/ic_launcher" 
      android:drawablePadding="5dp" 
      android:text="Call" 
      android:textColor="#FFFFFF" 
      android:textSize="15sp" /> 

     <Button 
      android:id="@+id/btnEmail" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:drawableLeft="@mipmap/ic_launcher" 
      android:drawablePadding="5dp" 
      android:text="Email" 
      android:textColor="#FFFFFF" 
      android:textSize="15sp" /> 

    </LinearLayout> 
</RelativeLayout> 

Примечание: Применить свой собственный и фона вводимого коэффициента, как у вас в ОП.

+0

спасибо за ответ У меня 1 que what isroid: drawableLeft = "@ mipmap/ic_launcher" ???? – Pritish

+1

Это изображение «Drawable», которое вы использовали в вашем коде 'android: drawableLeft =« @ drawable/PhoneCall », как это было. Сделайте так, как только вы просто следуете последовательности моего ответа. –

+0

Примите и подтвердите ответ, если вам будет полезно поблагодарить :). –

0

Заменить относительную линейность, вы получите желаемый результат.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#0B95BA" 
    android:minWidth="25px" 
    android:minHeight="25px"> 
    <LinearLayout 
     android:id="@+id/linearLayoutCont" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="5dp"> 
     <TextView 
      android:id="@+id/txtViewCont" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="Contact Billing" 
      android:gravity="center" 
      android:textSize="25sp" 
      android:textColor="#FFFFFF" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/linearLayoutContBillingCall" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@id/linearLayoutCont" 
     android:layout_marginTop="5dp"> 
     <Button 
      android:text="Call" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="15sp" 
      android:textColor="#FFFFFF" 
      android:layout_gravity="right" 
      android:background="@drawable/ButtonStyle" 
      android:id="@+id/btnContCall" 
      android:drawableLeft="@drawable/PhoneCall" /> 
     <Button 
      android:text="Email" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="15sp" 
      android:textColor="#FFFFFF" 
      android:layout_gravity="right" 
      android:background="@drawable/ButtonStyle" 
      android:id="@+id/btnEmail" 
      android:drawableLeft="@drawable/Email" /> 
    </LinearLayout> 
</LinearLayout> 
+0

Я хочу, чтобы LinearLayout для TextView и кнопок. – Pritish

+0

Вот что в коде. LineayLayout для Textview и LineraLayout для кнопок –

+0

Я уже реализую это, вы замените относительный макет LinearLayout. Я хочу TextView и Button в одном макете – Pritish