2013-11-14 3 views
0

다음 이미지는 내가 원하는 최종 결과를 표시 할 수 있습니다.다른 너비에 따른 Android 너비

enter image description here

A는 : 나는 작은 값을 입력하면 이미지 (사각형을 포함하는) 괜찮습니다.

B : 큰 값을 입력하면 이미지가 다시 조정되는 대신 동일한 너비로 유지됩니다.

C : 내가 원하는 최종 결과입니다. 사각형은 텍스트 뷰 값의 길이에 맞게 조절됩니다.

XML로만 결과를 얻을 수 있는지 알고 싶습니다. 나의 현재 코드는 다음과 같다 :

<ImageView 
    android:id="@+id/image" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:layout_width="150dp" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="0dp" 
    android:layout_marginTop="0dp" 
    android:background="@drawable/bg_sendsuccess" 
/> 

<TextView 
    android:id="@+id/numberId" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/numberId" 
    android:textSize="22sp" 
    android:textColor="#fff" 
    android:textStyle="bold" 
    android:layout_marginTop="3dp" 
    android:layout_marginRight="5dp" 
    android:layout_alignParentRight="true" 
/> 
+3

나는 당신의 요구를 이해하지 못합니다. – Broak

+0

질문을 이해할 수 없습니다. – njzk2

+0

방금 ​​내 글을 편집했습니다. – user2902515

답변

0

내가 무엇을 당신이 원하는 것은 당신의 TextView에 대한 9patch를 만드는 것입니다 추측. 9 접시를 TextView의 배경으로 설정해야합니다. 이것은 항상 귀하의 TextView 콘텐츠로 채워질 것입니다.

+0

내가 가지고 있다고 생각하지 않습니다. 튜토리얼이나 예제 코드를 제공 할 수 있습니까? – user2902515

1

사용중인 배경이 단순한 직사각형 인 경우 xml에서 해당 배경 이미지를 만들고 TextView의 배경으로 설정할 수 있습니다.

이라는 폴더를 res 폴더에 만듭니다. 그리고 그 drawable 폴더 안에 xml 파일 (모양)을 생성 (호출 할 수 있습니다 그것은 text_background.xml)

text_background.xml :

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 
<!-- Rounded Corner Settings --> 
<corners 
    android:bottomLeftRadius="8dp" 
    android:bottomRightRadius="8dp" 
    android:topLeftRadius="0dp" 
    android:topRightRadius="0dp" /> 

<!-- Rectangle Solid Color Settings --> 
<solid android:color="#ffffff" /> 

<!-- Rectangle Stroke Settings --> 
<stroke 
    android:width="1dp" 
    android:color="#000000" /> 

</shape> 

다음 layout XML에이 모양을 추가하려면 TextView

background
<TextView 
android:id="@+id/numberId" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/numberId" 
android:textSize="22sp" 
android:textColor="#fff" 
android:textStyle="bold" 
android:layout_marginTop="3dp" 
android:layout_marginRight="5dp" 
android:layout_alignParentRight="true" 
android:background="@drawable/text_background" 
/> 

그리고 더 이상 필요하지 않으므로 ImageView을 레이아웃에서 제거하십시오. 희망이 도움이

+0

나는 당신의 해결책이 내가 필요한 것이라고 생각한다. 그러나 text_background.xml을 색상 대신 이미지로 받아들이게하려면 어떻게해야합니까? – user2902515

+0

배경 이미지를 사용하려면 9 패치를 사용할 수 있습니다 (Damien R.). 9 패치에 대한 자세한 정보는 http://developer.android.com/tools/help/draw9patch.html 및 http://radleymarx.com/blog/simple-guide-to-9-patch/에서 확인할 수 있습니다. –

관련 문제