2014-10-31 5 views
2

, 나는 내가 이미지를 가지고 배경으로 설정하지 않으 enter image description hereAndroid에서이 UI를 달성하는 방법은 무엇입니까? 내 응용 프로그램 중 하나에서

아래 같을 것이다 선형 레이아웃 테두리를 작성해야합니다. 왜냐하면 나는 다양한 장치를 위해 다양한 크기의 이미지를 만들어야하기 때문입니다.

선형 레이아웃으로 레이아웃을 만들고 절대 위치 지정을 사용하여 텍스트 뷰를 배치하면 다른 장치에서 예상대로 표시되지 않을 수 있습니다.

그래서이 UI를 얻는 가장 좋은 방법은 무엇입니까?

+0

이 컨테이너에 대한 둥근 모서리를 가진 XML 형태 (사각형)을 사용합니다. 그게 전부입니다. OK, 전부는 아니지만, 내부 제목과 같은 불투명 한 배경색으로 제목 제목 TextView를 수정해야합니다. 테두리 선을 덮습니다. –

+0

'FrameLayout' 또는'RelativeLayout'을 사용하고 필요에 따라 필요한 뷰의 위치를 ​​정할 수 있습니다. –

+1

'그렇다면 다양한 크기의 이미지를 만들어야하기 때문에 9 패치를 들어 보셨습니까? – njzk2

답변

3

main_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_margin="10dp" 
      android:background="@drawable/Layout_selector" 
      android:orientation="vertical" > 
     </LinearLayout> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="MyText" 
      android:layout_marginLeft="50dp" 
      android:padding="1dp" 
      android:background="#fff" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </FrameLayout> 

</LinearLayout> 

을보십시오 : 당신이 글고의 배경으로 설정하려면

, 당신의 XML은 다음과 같이 보일 것입니다 Drawable 있음 Layout_selector.xml

,363,210
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:state_enabled="true" 
      android:state_pressed="true"> 
     <shape android:padding="5dp" android:shape="rectangle"> 
      <solid android:color="#FFF" /> 
      <stroke android:width="0.5dp" android:color="#29166f" /> 
      <corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" /> 
     </shape> 
    </item> 
    <item android:state_enabled="true" android:state_focused="true"> 
     <shape android:padding="5dp" android:shape="rectangle"> 
      <solid android:color="#FFF" /> 
      <stroke android:width="0.5dp" android:color="#29166f" /> 
      <corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" /> 
     </shape> 
    </item> 
    <item android:state_enabled="true"> 
     <shape android:padding="5dp" 
      android:shape="rectangle"> 
      <solid android:color="#FFF" /> 
      <stroke android:width="0.5dp" android:color="#29166f" /> 
      <corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" /> 
     </shape> 
    </item> 

</selector> 

출력은 다음과 같습니다

Output

0

RelativeLayout을 사용하십시오. 먼저 경계가있는 EditText 상자를 만듭니다. 그런 다음 RelativeLayout을 사용하여 TextView - marginpaddingTextView에 맞춰 원하는 효과를 얻으십시오.

+0

FrameLayout 더 좋을지도 모릅니다. –

0

이제 여러 이미지를 만들지 않아도되도록 이미지를 배경으로 설정하는 것을 피하고 싶지만 Android Asset Studio에 대해 들어 보았습니다. 나는이 멋진 웹 사이트에 대해 듣기 전에 자원 (특히 9 패치)을 다루는 것을 싫어한다.

이 사이트를 사용하여 이미지를 업로드하고 이미지 용 9 패치 파일을 만드십시오. 나는 신축성있는 영역을 이미지의 중간에 작은 사각형으로 설정 한 다음 Android 자산 스튜디오가 나머지 작업을 수행 할 것을 제안합니다.

일단 모든 작업을 완료했다면, 이것을 RelativeLayout 대신 EditText의 배경으로 만들고 싶습니다.하지만 UI에서 가장 잘 보이는 것을 결정하는 것은 당신에게 달려 있습니다.

<EditText 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_alignLeft="@+id/relativeLayout1" 
    android:background="@android:drawable/imageFile" 
    /> 
관련 문제