ImageView 및 TextView를 포함하는 LinearLayout 대신 복합 드로어 블을 사용하는 방법
내 코드에 대해 새로운 Lint 도구를 실행하십시오. 많은 좋은 제안이 있었지만 이해할 수는 없습니다.
이 태그와 그 하위 요소는 하나의 복합 드로어 블로 대체 될 수 있습니다
문제 : 복합 드로어 블을 사용하여 현재 노드를 TextView로 바꿀 수 있는지 확인합니다.
ImageView 및 TextView가 포함 된 LinearLayout은 복합 드로어 블로보다 효율적으로 처리 할 수 있습니다.
그리고 여기 내 레이아웃이 있습니다
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/upImage"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:scaleType="centerInside"
android:src="@drawable/up_count_big">
</ImageView>
<TextView
android:id="@+id/LikeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginBottom="1dp"
android:textColor="@color/gray"
android:textSize="16sp"
android:layout_gravity="center_vertical">
</TextView>
</LinearLayout>
이 경우 컴파운드를 그릴 수있는 방법에 대한 구체적인 예를 제공 할 수 있습니까?
TextView
왼쪽, 위, 오른쪽 및 아래쪽에 각각 하나씩 4 개의 복합 드로어 블이 제공됩니다.
귀하의 경우에는 LinearLayout
및 필요하지 않습니다 ImageView
. 에 추가 android:drawableLeft="@drawable/up_count_big"
하십시오 TextView
.
자세한 내용은 TextView # setCompoundDrawablesWithIntrinsicBounds 를 참조하십시오.
어떤 이유로 코드를 통해 추가 해야하는 경우 다음을 사용할 수 있습니다.
mTextView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
왼쪽, 위, 오른쪽 아래는 Drawables입니다.
이것에 추가하려면이 게시물에 따라 드로어 블의 너비와 높이를 정의하는 것이 중요합니다.
(그의 코드 작동)
일반적인 복합 드로어 블 구현을 사용할 수 있지만 드로어 블 크기를 정의해야하는 경우이 라이브러리를 사용하십시오.
https://github.com/a-tolstykh/textview-rich-drawable
다음은 사용법의 작은 예입니다.
<com.tolstykh.textviewrichdrawable.TextViewRichDrawable
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text"
app:compoundDrawableHeight="24dp"
app:compoundDrawableWidth="24dp" />
'IT' 카테고리의 다른 글
자바 대표? (0) | 2020.05.14 |
---|---|
TensorFlow에서 Session.run ()과 Tensor.eval ()의 차이점은 무엇입니까? (0) | 2020.05.14 |
배열 이름이 포인터입니까? (0) | 2020.05.14 |
PHP 사이트 URL 프로토콜 가져 오기-http 및 https (0) | 2020.05.14 |
두 객체 사이의 일반적인 깊은 차이 (0) | 2020.05.14 |