Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to make all elements inside LinearLayout same size?

Tags:

android

layout

I would like to create a dialog to display a video title and tags. Below text I would like to add buttons View, Edit and Delete and make these elements same size. Does anyone know how to modify .xml layout file in order to make elements inside LinearView same size?

The current layout file looks like this:

<LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"      android:orientation="vertical">      <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="vertical">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:id="@+id/txtTitle" android:text="[Title]" >           </TextView>            <TextView                android:layout_width="wrap_content"               android:layout_height="wrap_content"                android:id="@+id/txtTags"                           android:text="[Tags]" >           </TextView>      </LinearLayout>      <LinearLayout          android:layout_width="fill_parent"          android:layout_height="wrap_content"          android:orientation="horizontal">          <Button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btnPlay"             android:text="View">         </Button>          <Button              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:id="@+id/btnEdit"              android:text="Edit">         </Button>          <Button              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:id="@+id/btnDelete"              android:text="Delete">         </Button>      </LinearLayout>  </LinearLayout> 

I would appreciate if anyone could show the solution by modifying the pasted file content.

Thanks!

like image 381
Niko Gamulin Avatar asked Jul 24 '09 11:07

Niko Gamulin


People also ask

How do you align text in LinearLayout?

If in linearlayout your orientation vertical, you can put the textview in the "horizontal center" by android:layout_gravity="center" . For centering textview vertically you need to set layout_height of textview to match_parent and set android:gravity to "center".

Can we use RelativeLayout inside LinearLayout?

Using Linear Layout Inside Relative Layout With Example In Android Studio. Linear Layout can be used inside relative layout since one layout can be nested in other layout in XML.

Which is better LinearLayout or RelativeLayout?

Relativelayout is more effective than Linearlayout. It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.

What is the difference between Framelayout and LinearLayout in Android?

Frame Layout: This is designed to block out an area on the screen to display a single item. Linear Layout: A layout that arranges its children in a single column or a single row. Relative Layout: This layout is a view group that displays child views in relative positions.


2 Answers

Use android:layout_width="0px" and android:layout_weight="1" on the three Buttons. That says the buttons should take up no more than 0 pixels, but the three of them should split any extra space between them. That should give you the visual effect you wish.

like image 144
CommonsWare Avatar answered Oct 05 '22 23:10

CommonsWare


Another way is to make android:layout_width="fill_parent" and android:layout_weight="1" this will also works fine!!!

like image 26
Eby Avatar answered Oct 06 '22 01:10

Eby