안드로이드 레이아웃 :이 태그와 그 하나는 대체 될 수 있습니다. 및 복합 드로어 블
특정 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 문서!
위의 코드를 따랐을 때 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>
ImageView 및 TextView를 변경하지 않으려면 AndroidManifest.xml에서 버전을 다음과 같이 변경할 수 있습니다.
<uses-sdk`
android:minSdkVersion="8"
android:targetSdkVersion="18"
/>
버전이 android : targetSdkVersion = "17"이면 "18"로 변경됩니다.
이것이 바로 잡기를 바랍니다. 내가 해냈고 제대로 해냈어
추가 tools:ignore="UseCompoundDrawables"
에 <LinearLayout>
.
또 다른 접근 방식은 ViewImage를 다른 LinearLayout에 포함하는 것입니다 (단독 ID로 처리 할 수 있음).
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blue_3"
android:layout_gravity="center_horizontal"
android:paddingTop="16dp" />
</LinearLayout>
<TextView
android:id="@+id/tvPrompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="16dp"
android:text="@string/xy" />
This tag and its children can be replaced by one <TextView/> and a compound drawable
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:contentDescription="."
android:padding="3dp"
android:src="@drawable/tab_home_btn">
</ImageView>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="首页"
android:textSize="10sp"
android:textColor="#ffffff">
</TextView>
</LinearLayout>
'IT' 카테고리의 다른 글
파선 길이 획 길이 및 획 사이의 거리 제어 (0) | 2020.08.07 |
---|---|
Sublime Text의 기본 글꼴은 무엇입니까? (0) | 2020.08.07 |
C #에서 메모장으로 파일 열기 (0) | 2020.08.07 |
Dapper로 중첩 된 개체 목록을 매핑하는 방법 (0) | 2020.08.07 |
프로그래밍 방식으로 자바 펼쳐 함수에 코드 추가 (0) | 2020.08.07 |