Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to layout view right aligned and bottom of an LinearLayout

Tags:

android

I am trying to layout 1 textview (upText) left aligned and 1 textview (downText) and an image view (image) both on the same line and right aligned.

how can I do that? I tried that, but both 'textview' and image view at left aligned.

        <TextView
            android:id="@+id/uptext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="left"/>
        <TextView
            android:id="@+id/downtext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:gravity="right|bottom"/>
        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right|bottom"/>
    </LinearLayout>
like image 846
michael Avatar asked Apr 18 '10 21:04

michael


People also ask

How do I fix the view to the bottom of LinearLayout?

You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight . Just play around with the values until you find out which works best. The resulting heights of header and footer would dynamically change with the screensize.

How do you move a linear layout to the right?

Try to change the layout_width to android:layout_width="match_parent" because gravity:"right" aligns the text inside the layout_width, and if you choose wrap content it does not have where to go, but if you choose match parent it can go to the right.

How do you align views in linear layout?

To center align LinearLayout, assign android:gravity attribute of this LinearLayout with the value “center”. Let us create an Android application with LinearLayout containing two Button widgets as children. We shall center align these children using gravity attribute.

What is the default orientation of a LinearLayout?

The default orientation is horizontal.


1 Answers

Don't use a LinearLayout. Use a RelativeLayout, with

  • your first TextView set with android:layout_alignParentLeft="true"
  • your second TextView set with android:layout_alignParentBottom="true" and android:layout_alignParentRight="true"
  • something similar for your ImageView, which presently looks like it is going to overlap the second TextView
like image 191
CommonsWare Avatar answered Sep 20 '22 10:09

CommonsWare