【发布时间】:2017-08-23 16:51:04
【问题描述】:
我必须在 LinearLayout 中使 TextView 水平,在 ConstraintLayout 中使 TextView 垂直。
问题是 TextView 的属性wrap_content 不起作用。
这是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.black_swan.myapplication11.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
这是项目的图片:
【问题讨论】:
-
停止使用嵌套的 LinearLayout 或移除 layout_weight
-
没有嵌套的 linerlayout 包装内容工作正常,但为什么它不适用于嵌套的 linerlayout @cricket_007
-
因为 layout_weight 覆盖了 wrap_content
-
好的,谢谢@cricket_007
标签: android android-linearlayout android-wrap-content