1

I have to make a TextView horizontal inside a LinearLayout and vertical inside a ConstraintLayout.
The problem is that the property wrap_content of the TextView is not working.
This is the xml file:

<?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>

and this is the image of the project:

here the image of design

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
black swan
  • 47
  • 8

2 Answers2

1

Remove android:layout_weight="1" on TextView. Further more It seems that your TextView's parent LinearLayout is not useful. Try not using unnecessary nested layouts.

Aalap Patel
  • 2,058
  • 2
  • 17
  • 31
  • it work when I remove android:layout_weight="1" on TextView , thank you ... I will accept your answer after 2 minutes – black swan Aug 23 '17 at 16:59
0

If you use a layout weight, typically, you would use a size of 0dp for the corresponding direction.

  • 0dp width for horizontal
  • 0dp height for vertical

When you use the weight, then wrap_content size is overridden

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245