특정 XML 파일에서 레이아웃을 실행하면 다음과 같은 결과가 나타납니다.
This tag and its children can be replaced by one <TextView/>
and a compound drawable
다음 xml 코드에 대해 수행해야하는 변경 사항 :
<LinearLayout android:id="@+id/name_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="@drawable/grouplist_single_left_grey_area" >
<ImageView android:id="@+id/photo_image"
android:layout_width="@dimen/thumbnail_width"
android:layout_height="@dimen/thumbnail_height"
android:paddingBottom="5dip"
android:paddingTop="5dip"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:layout_marginRight="5dip"
android:clickable="true"
android:focusable="true"
android:scaleType="fitCenter"
android:src="@*android:drawable/nopicture_thumbnail"
android:background="@drawable/photo_highlight" />
<TextView android:id="@+id/name"
android:paddingLeft="5dip"
android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
다음은 화면에 나타나는 모습입니다.
카메라 아이콘이 기본값입니다. 이를 클릭하면 사용자에게 다른 이미지를 선택할 수있는 옵션이 제공됩니다.
답변
Romain Guy의 답변을 확장하기 위해 여기에 예가 있습니다.
전에:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="My Compound Button" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_drawable" />
</LinearLayout>
후:
<TextView
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My Compound Button"
android:drawableRight="@drawable/my_drawable" android:padding="5dp" />
답변
병합 TextView
과를 ImageView
텍스트 뷰의 사용에 의해, 하나에 setCompoundDrawable*()
방법을, 또는 사용 android:drawableLeft
.
답변
이것에 대한 추가 puntos도 얻으려고 노력할 것이라고 생각 android:drawablePadding
했습니다.. https://stackoverflow.com/a/6671544/1224741
답변
때로는 복합 드로어 블 (들) 로 대체 ImageView
(또는 여러 개) 및 TextView
하나로 대체 할 수 있습니다 TextView
. 네이티브 API와이 TextViewRichDrawable 라이브러리를 사용하여 복합 드로어 블에 적용 할 수있는 매개 변수는 많지 않지만 LinearLayout을 사용하는 대신 하나의 TextView를 관리 할 수 있다면 반드시 사용해야합니다. .
복합 드로어 블에 적용 할 수있는 속성 및 매개 변수 목록 :
크기 : ( 예, 정말 ) :
<com.tolstykh.textviewrichdrawable.TextViewRichDrawable
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text"
app:compoundDrawableHeight="24dp"
app:compoundDrawableWidth="24dp"/>
심지어 세트 벡터 자원 당김과 같은 :
<com.tolstykh.textviewrichdrawable.TextViewRichDrawable
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text"
app:drawableTopVector="@drawable/some_vector_drawble"
app:drawableEndVector="@drawable/another_vector_drawable" />
네이티브 API를 사용한 Drawable의 패딩 android:drawablePadding
-> 링크
다음은 예입니다.
답변
LinearLayout
포함하는 ImageView
A는 TextView
보다 효율적으로 화합물 그리기로 처리 할 수 (하나
TextView
은 USING, drawableTop
, drawableLeft
, drawableRight
및 / 또는 drawableBottom
하나 개 이상의 이미지 텍스트에 인접 그릴 속성).
두 위젯이 여백을 사용하여 서로 오프셋 된 경우 drawablePadding
속성 으로 대체 할 수 있습니다 .
Eclipse 플러그인에서이 변환을 수행하는 Lint 빠른 수정이 있습니다.
From : Android 공식 API 문서!
답변
추가 tools:ignore="UseCompoundDrawables"
에 <LinearLayout>
.
답변
위의 코드를 따랐을 때 TextView 내부의 텍스트가 제대로 설정되지 않았습니다. 질문에 표시된 것을 달성하려면 중력을 중심으로 설정해야합니다.
textview는 다음과 같습니다.
<TextView
android:id="@+id/export_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableLeft="@drawable/up_arrow"
android:drawableStart="@drawable/up_arrow"
android:gravity="center|start"
android:text="....."
android:textSize="@dimen/font_size15" >
</TextView>