【发布时间】:2019-02-26 06:34:31
【问题描述】:
我有这个布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/account_display_name"
style="@style/AccountDataDisplayName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
<TextView
android:id="@+id/account_name"
style="@style/AccountDataAccountName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
tools:text="emailisverylongaswellwewantittogettruncated@gmail.longdomain.com"/>
</LinearLayout>
当account_display_name 的可见性动态切换为 GONE 和 VISIBLE 时。
在一种情况下,只有 accountName 可见 那么 coumpoundDrawable 图标似乎太高了。
在其他情况下,accountName 和 DisplayName 都是可见的。 那么 coumpoundDrawable 图标似乎太低了。
*我会尽快添加布局isspector图像。
这是java代码:
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
targetTextView, null, null, drawable, null);
"setCompoundDrawablesRelativeWithIntrinsicBounds"怎么会在同一个资源上做出不同的居中?
我猜是因为accountName是wrap_content所以单独的时候更大?
居中和定位的什么逻辑导致了这种差异?也许我在 compundDrawable 定位中遗漏了一些东西。
或者我应该如何解决这个问题?
layout_gravitig:"center_vertical" 在 accountName 和 DisplayName 的 xml 中?
【问题讨论】:
标签: android text layout center drawable