微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – layout_gravity无效

为什么我的TextView不正确?

更新:好吧,现在我不需要将TextView设置为右侧.现在,为什么layout_gravity不能按预期工作非常有趣,即 – 将View设置为父容器内的位置.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:minHeight="?android:attr/listPreferredItemHeight"
              style="@style/activated_item"
              android:orientation="horizontal">

    <CheckBox
        android:id="@+id/star"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="8dp"
        style="?android:attr/starStyle"/>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_marginLeft="8dp"
        android:layout_gravity="right" //////// HERE I AM 
        android:textStyle="bold"
        android:textColor="@color/item_text_color"/>

</LinearLayout>

解决方法

尝试使用 gravity而不是layout_gravity.

原文地址:https://www.jb51.cc/android/317025.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐