2015-04-13 3 views
0

Я пытаюсь выяснить, как разместить границу вокруг нескольких видов для приложения Android, над которым я работаю. Похоже, это должно быть очень просто, но я не могу понять это. Я следующий файл XML сохраняется в моей вытяжке папке:Android: Помещение границы вокруг нескольких видов

<?xml version="1.0" encoding="UTF-8"?> 

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <solid android:color="#ffffff" /> 
    <stroke android:width="1dp" android:color="#000000"/> 
    <padding android:left="10dp" 
     android:top="10dp" 
     android:right="10dp" 
     android:bottom="10dp"/> 

</shape> 

Я тогда несколько TextViews и один простой вид, как часть моего основного Android приложения:

<TextView 
    android:id="@+id/tvTitle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:background="@drawable/backTop" 
    android:gravity="center" 
    android:text="@string/title" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/tvProvHeader" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignStart="@+id/tvTitle" 
    android:layout_below="@+id/tvTitle" 
    android:layout_marginEnd="20dp" 
    android:layout_marginStart="30dp" 
    android:layout_marginTop="35dp" 
    android:text="@string/providerHeader" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 

<TextView 
    android:id="@+id/tvSigStrHeader" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/tvProvHeader" 
    android:layout_alignBottom="@+id/tvProvHeader" 
    android:layout_marginStart="50dp" 
    android:layout_toEndOf="@+id/tvProvHeader" 
    android:text="@string/sigStrHeader" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 

<View 
    android:layout_width="fill_parent" 
    android:layout_height="4dp" 
    android:layout_alignStart="@+id/tvTitle" 
    android:layout_alignEnd="@+id/tvTitle" 
    android:layout_marginLeft="30dp" 
    android:layout_marginRight="30dp" 
    android:layout_below="@+id/tvProvHeader" 
    android:background="#cccccc" /> 

<TextView 
    android:id="@+id/tvProv1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignStart="@+id/tvProvHeader" 
    android:layout_below="@+id/tvProvHeader" 
    android:layout_marginTop="16dp" 
    android:text="" /> 

<TextView 
    android:id="@+id/tvProv2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignStart="@+id/tvProv1" 
    android:layout_below="@+id/tvProv1" 
    android:text="" /> 

<TextView 
    android:id="@+id/tvProv3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignStart="@+id/tvProv2" 
    android:layout_below="@+id/tvProv2" 
    android:text="" /> 

<TextView 
    android:id="@+id/tvProv4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignStart="@+id/tvProv3" 
    android:layout_centerVertical="true" 
    android:text="" /> 

Я хотел бы разместить границу (от рисованного) вокруг всех, кроме первого TextView. Я посмотрел на использование ViewGroup, но я не могу понять, как это сделать. Как мне это сделать?

ответ

3

Сделайте LinearLayout в своем корневом макете. Затем в этом макете поставьте все TextViews. Затем установите линейный макет фона на ваш drawable.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:id="@+id/tvTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/backTop" 
     android:gravity="center" 
     android:text="@string/title" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <LinearLayout 
     android:orientation="vertical" 
     android:id="@+id/llLinearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/your_borderShape> 

     ///All of the other text views here 

    <LinearLayout/> 

Вы не должны использовать LinearLayout, кстати. RelativeLayout - другой популярный вариант.

+0

Спасибо, я пробовал оба, и я продолжаю получать эти предупреждения: http://oi58.tinypic.com/2sb25hz.jpg Могут ли они безопасно игнорироваться или мне не хватает шага? – DerStrom8

+0

LinearLayout не разрешает выровнять старт или что-либо, что требует другого представления, чтобы указать свою позицию. Это то, для чего вы бы использовали relativeLayout. Линейная компоновка просто добавит все виды один за другим –

+0

: Facepalm: Я знал это! = P Собираюсь дать этому ходу .... – DerStrom8

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