layout_weight的使用陷阱
<?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:orientation="horizontal" >
<LinearLayout
android:id="@+id/linear_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="15dp"
android:text="评论 "
android:textColor="@color/six1"
android:textSize="@dimen/twoTitle"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="@+id/tv_supportWish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/redClicked"
android:gravity="center"
android:padding="15dp"
android:text="支持Ta"
android:textColor="@color/white"
android:textSize="@dimen/twoTitle" />
</LinearLayout>
</LinearLayout>
看样子是左右平分了,其实没有,因为左右的文本不是占据一样的宽度的,左边的少两个字节
解决方案1
左边的文本改成 android:text="评论 \u3000",这样左右文本占用一样的字节,就会平分了
解决方案2
android:layout_width="0dp"
android:layout_weight="1",这样也平分了
<?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:orientation="horizontal" >
<LinearLayout
android:id="@+id/linear_share"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="15dp"
android:text="评论 "
android:textColor="@color/six1"
android:textSize="@dimen/twoTitle"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="@+id/tv_supportWish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/redClicked"
android:gravity="center"
android:padding="15dp"
android:text="支持Ta"
android:textColor="@color/white"
android:textSize="@dimen/twoTitle" />
</LinearLayout>
</LinearLayout>
更多相关文章
- Android: Failure [INSTALL_FAILED_DEXOPT] and Failure [INSTALL
- Android读取SD卡.TXT文本内容
- 安卓 文本 滑动 android text slide
- Android Studio build失败情况解决方案
- android 如何让文本中某个关键字高亮显示?
- 关于android录音权限被用户禁用的问题解决方案
- Android Studio安装后Fetching android sdk component informati