2016-10-14 2 views
-2

Ich habe eine LinearLayout und ich möchte eine Grenze dafür setzen. Es sollte wie folgt aussehen.Android: Border für LinearLayout

enter image description here

Das ist mein Layout,

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/content_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".activities.AddInfoMainActivity" 
    tools:showIn="@layout/app_bar_main"> 


    <LinearLayout 
     android:id="@+id/add_info_layout_one" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:id="@+id/add_info_layout_one_one" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="2dp" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <ImageView 
       android:id="@+id/add_info_layout_one_img01" 
       android:layout_width="match_parent" 
       android:layout_height="48dp" 
       android:layout_marginTop="24dp" 
       android:src="@drawable/sample01" /> 

      <TextView 
       android:id="@+id/add_info_layout_one_txtView01" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="24dp" 
       android:text="@string/add_info_txt_one_01" 
       android:textAlignment="center" 
       android:textSize="20sp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="24dp" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/add_info_layout_one_two" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="2dp" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <ImageView 
       android:id="@+id/add_info_layout_one_img02" 
       android:layout_width="match_parent" 
       android:layout_height="48dp" 
       android:layout_marginTop="24dp" 
       android:src="@drawable/sample02" /> 

      <TextView 
       android:id="@+id/add_info_layout_one_txtView02" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="24dp" 
       android:text="@string/add_info_txt_one_02" 
       android:textAlignment="center" 
       android:textSize="20sp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="24dp" /> 

     </LinearLayout> 


    </LinearLayout> 
</RelativeLayout> 

Util jetzt ich keine Art für mein Layout verwenden.

Haben Sie irgendwelche Ideen?

+1

Was haben Sie versucht? 'Android: Höhe'? Ein Neun-Patch-Hintergrundbild? Etwas anderes? – Karakuri

+1

Sie müssen die Kartenansicht als übergeordnetes Element verwenden und darin das lineare Layout mit Bild und Text verwenden. Setzen Sie die Höhe wie gewünscht in der cardview -Eigenschaft –

+1

Fügen Sie Ihr LinearLayout stattdessen mit einem 'CardView'-Widget zusammen. – Wizard

Antwort

5

Um Rahmen festzulegen, können Sie eine XML-Datei in Ihrem Zeichensatz mit dem folgenden Code erstellen.

border.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
     <stroke android:width="5dip" android:color="@android:color/white" /> 
</shape> 

und von Ihrem Linearlayout stellen Sie Ihren Hintergrund

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com.... 
    android:background="@drawable/border"> 

    <!--- code here ---> 

</LinearLayout> 

aber Basis auf Ihrem Bild, das Sie suchen cardView. Versuchen Sie, nach cardview zu suchen.

klicken Sie auf diese link zum Beispiel und Tutorial für cardview.

2

Versuchen wie folgt aus:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/_5sdp" 
     app:cardBackgroundColor="@color/white" 
     app:cardCornerRadius="@dimen/_3sdp"> 

     <LinearLayout 
      android:id="@+id/add_info_layout_one" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <LinearLayout 
       android:id="@+id/add_info_layout_one_one" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="2dp" 
       android:layout_weight="1" 
       android:orientation="vertical"> 

       <ImageView 
        android:id="@+id/add_info_layout_one_img01" 
        android:layout_width="match_parent" 
        android:layout_height="48dp" 
        android:layout_marginTop="24dp" 
        android:src="@drawable/sample01" /> 

       <TextView 
        android:id="@+id/add_info_layout_one_txtView01" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="24dp" 
        android:text="@string/add_info_txt_one_01" 
        android:textAlignment="center" 
        android:textSize="20sp" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="24dp" /> 

      </LinearLayout> 

     </LinearLayout> 

</android.support.v7.widget.CardView> 
2

Verwenden Karte Ansicht, wenn Sie Effekt wollen Schatten. Fügen Sie die Kartenhöheneigenschaft card_view:cardElevation="4dp" so oft ein, wie Sie möchten.

Oder fügen Sie diese Zeichnungsdatei in Ihrem Ordner drawable hinzu.

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 

    <gradient 
     android:angle="0" 
     android:centerColor="#ffffff" 
     android:centerX="35%" 
     android:endColor="#ffffff" 
     android:startColor="#ffffff" 
     android:type="linear"/> 

    <size 
     android:width="80dp" 
     android:height="80dp"/> 
    <stroke 
     android:width="2dp" 
     android:color="#eaeaea"/> 
</shape>