【问题标题】:SVG into coumpoundDrawable doesn't look centered to textSVG 到 coumpoundDrawable 看起来并不以文本为中心
【发布时间】: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"accountNameDisplayName 的 xml 中?

【问题讨论】:

    标签: android text layout center drawable


    【解决方案1】:

    试试这个

    TextView textViewCompat= convertView.findViewById(R.id.textViewCompat);
    textViewCompat.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_your_svg, 0, 0, 0);
    

    【讨论】:

    • 根据android doc,它是一样的。为什么你认为它不同
    • 好吧哈哈!只需在 android 文档中获取您的回复即可。 (:
    • 不确定我理解你的意思。为什么你认为它不一样?
    【解决方案2】:

    通常复合可绘制重力是中心,您需要检查 SVG 视口边界以查看它们是否将矢量定位在中心或矢量上方有一点顶部填充。

    【讨论】:

    • 但即使有顶部填充 - 为什么有时它会太高?我的意思是有不一致的地方
    • 在你提供的图片中,与文字相比,我觉得drawable并不太高。
    • 但是为什么在处理第二张图片时它的居中不一样?
    猜你喜欢
    • 2021-04-23
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多