2016-10-14 3 views
-2

나는 LinearLayout을 가지고 있으며 경계를 지정하고 싶습니다. 그것은 아래처럼 보일 것입니다. 안드로이드 : LinearLayout 용 테두리

enter image description here

<?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> 

백분율이 지금은 내 레이아웃 어떤 스타일을 사용하지 한 것으로, 나의 레이아웃입니다.

아이디어가 있으십니까?

+1

에서 받아? 'android : elevation'? 9 패치 배경 이미지? 다른 것? – Karakuri

+1

당신은 카드보기를 부모로 사용해야하며 cardview 속성에서 원하는대로 이미지와 텍스트와 함께 선형 레이아웃을 사용해야합니다. –

+1

대신에 CardView 위젯으로 LinearLayout을 마무리하십시오. – Wizard

답변

5

테두리를 설정하려면 아래 코드를 사용하여 드로어 블에 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> 

하고있는 LinearLayout에서

border.xml은 배경

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

    <!--- code here ---> 

</LinearLayout> 

을 설정하지만, 이미지에 기반 당신은 cardView 찾고 있습니다. cardview을 검색해보십시오.

예를 들어 link을 클릭하고 cardview에 대한 자습서를 클릭하십시오.

2

는 다음과 같이하십시오 :

<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

사용 카드보기를하면 효과를 그림자합니다. 카드 표고 속성 card_view:cardElevation="4dp"을 dp를 원하는만큼 설정하십시오.

또는이 드로어 블 파일을 drawable 폴더에 추가하십시오.

<?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>