Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a TextView below an other one in Android with XML files?

I am pretty sure that a parameter will do the trick but I can't find the one I am looking for.

I am trying to display one TextView -file_type- below the file_title TextView.

What would be the parameter that I should add to the file_type TevxtView block to come under the file_title TextView block ?

There is what I am doing :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">

  <ImageView android:id="@+id/file_type_logo"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="25px"
      android:paddingTop="25px" />

  <TextView android:id="@+id/file_title"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:paddingLeft="30px"
     android:textSize="22sp"
     android:background="#FF0000"
     android:textColor="#FFFFFF" />

  <TextView android:id="@+id/file_type"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:paddingLeft="30px"
     android:paddingTop="10px"
     android:layout_gravity="bottom"
     android:textSize="22sp"
     android:background="#FF0000"
     android:textColor="#FFFFFF" />

</LinearLayout>

Thank you ,

like image 873
Spredzy Avatar asked Nov 07 '10 15:11

Spredzy


1 Answers

By default linearlayout wraps things horizontally. If you want the imageview to be at the left of the both textviews (that are wrapped vertically), use following:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">

  <ImageView .../>

  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:orientation="vertical">

    <TextView1..../>

    <TextView2..../>

 </LinearLayout> 
</LinearLayout>

Or you can just pass the parameter android:orientation="vertical" to the top level LinearLayout. Have a look at RelativeLayout definition as well.

like image 194
Mika Vatanen Avatar answered Oct 06 '22 01:10

Mika Vatanen