Layout_gravity not working inside LinearLayout

I have the following code:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="0dp"
        android:layout_height="150dp"
        android:layout_weight="3"
        android:inputType="textMultiLine" >
    </EditText>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_weight="1"
        android:text="@string/new_post_txt_description" />
</LinearLayout>

Apparently android:layout_gravity="top"not moving TextViewup. Does anyone know how to achieve this?

PS

I saw some ideas about using RelativeLayout, but in my case, I need both controls to be next to each other and use the weight attribute, as in the example.

Thank!

+3
source share
3 answers

Changing the textView for this worked for me

<TextView
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:gravity="top"
    android:layout_weight="1"
    android:text="TEST" />

This uses gravity instead of layout_gravity, but since the height of the textView is set to fill_parent, it has the same effect

android: View, . android: layout_gravity .

+9

LinearLayout . .

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

, . , . 2, LinearLayout .

+3

layout_gravity does not work unless you add android:orientation="vertical"to the linear layout.

for instance

<?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="match_parent"
android:orientation="vertical" >

<!-- Your Code Here -->   

</LinearLayout>
0
source

All Articles