2013-04-22 2 views
5

일부 자동 완성 및 텍스트 상자가있는 linearLayout이 있습니다. 선형 레이아웃에 도형 (직사각형)을 삽입하고 싶습니다. 나는 어떻게 이것을 달성 할 수 있는가. 나는 안드로이드에 새로 왔어.LinearLayout Android에 도형 추가

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"  
    android:padding="5dp" 
    android:id="@+id/layout"> 

    <AutoCompleteTextView android:id="@+id/autocompleteCountry" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/CONTRY_LABEL" 
     /> 
    <AutoCompleteTextView android:id="@+id/locationAutoCompleteFrom" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/from" 
     android:visibility="gone" 
     /> 
    <AutoCompleteTextView android:id="@+id/locationAutoCompleteTO" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/to" 
     android:visibility="gone" 
     /> 
<!-- <Button android:id="@+id/buttonRoute" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/buttonRouteText" 
     android:enabled="false" 
     android:clickable="true" 
     /> 
    --> 

+0

에 이동에 도움이 될 수 want.Hope 어떤 모양을 그릴 수있는 LinearLayout 클래스를 구현하여 사용자 정의보기를 생성하고) (MTD를 onDraw는 오버라이드 (override) 운영자 추천 수 : //www.gadgetsaint.com/tips/dynamic-square-rectangular-layouts-android/#.WRRjMvl96H s – ASP

답변

9

스타일을 추가하려는 구성 요소의 배경으로 ShapeDrawable을 사용해야합니다.

셰이프 드로어 블은 다음과 같은 구문을 사용하여 XML로 생성됩니다.이 셰이프 드로잉은 둥근 모서리가있는 직사각형을 보여 주지만 원하는 모양으로 사용자 정의 할 수 있습니다. 이 파일 (이름 background_square.xml 또는 무엇이든)은 당신의 당김 폴더에 저장해야합니다

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:radius="5dp" /> 
    <solid 
     android:color="@color/primary_grey" /> 
</shape> 

를 그리고, 당신이보기에 추가 할 때, 당신은 당신의 XML에 다음 구문을 사용할 수 있습니다

android:background="@drawable/background_square" 
+2

이 모양을 ImageView의 소스로 사용했으나 그렇지 않은 경우 괜찮습니다! 감사! –

+0

이 배경을 LinearLayout의 ImageView, TextView보기에 추가 할 수 있습니다 (이 경우 모든보기는 Android와 관련하여 동일합니다). – Booger

2

당신은 당신이 단순히 레이아웃 내에서 중첩 된 레이아웃 (LinearLayout을 말한다)을 추가 사각형을 추가하려는 경우

아래처럼 뭔가를하고 android:background="yourcolor" 설정할 수 있습니다 // 당신은 해시를 사용하여 색상을 추가 할 수 있습니다 색상 값

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"  
android:padding="5dp" 
android:id="@+id/layout"> 

<AutoCompleteTextView android:id="@+id/autocompleteCountry" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="@string/CONTRY_LABEL" 
    /> 
<AutoCompleteTextView android:id="@+id/locationAutoCompleteFrom" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="@string/from" 
    android:visibility="gone" 
    /> 
//suppose you want to add your rectangle here 
<LinearLayout 
android:id="@+id/rectangle" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"  
android:background="yourcolor" 
> 
</LinearLayout> 

크기, 여백 등을 말하면 모든 상대 속성이 변경됩니다.

+0

실제로 올바른 경로에 있지만 Rectagle을 추가해야하는 경우 LinearLayout을 사용할 필요가 없습니다. View를 대신 사용하십시오. LineraLayout을 스타일링하는 데 사용하는 모든 주요 속성을 가지고 있으며 레이아웃 프로세스의 계산 측면에서 더 가벼울 것입니다. –

0

나는 유는이 HTTP를 확인, 동적 직사각형 레이아웃을 위해 올바른 방향으로