Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between android:width and android:layout_width

in the following code why the appearance of the radio button changes when i set

 android:layout_width="fill_parent"

and

 android:width="fill_parent"

i am talking about the _radio button _ whose id is left

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

<RadioGroup
    android:id="@+id/orientation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5px" >

    <RadioButton
        android:id="@+id/horizontal"
        android:text="horizontal" />

    <RadioButton
        android:id="@+id/vertical"
        android:text="vertical" />
</RadioGroup>

<RadioGroup
    android:id="@+id/gravity"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5px"

     >

    <RadioButton
        android:id="@+id/left"
        android:text="left"
        android:layout_width="fill_parent"   // I am talking about this line
        />

    <RadioButton
        android:id="@+id/center"
        android:text="center" />

    <RadioButton
        android:id="@+id/right"
        android:text="right" />
</RadioGroup>

like image 715
HforHisham Avatar asked Jun 24 '12 23:06

HforHisham


People also ask

What is Android Layout_width?

layout_width : the width, either an exact value, WRAP_CONTENT , or FILL_PARENT (replaced by MATCH_PARENT in API Level 8) layout_height : the height, either an exact value, WRAP_CONTENT , or FILL_PARENT (replaced by MATCH_PARENT in API Level 8) Parameters.

What is difference between Wrap_content and Match_parent?

Conclusion : fill_parent and match_parent are the same, used when we want the height or width of a view to be as big as its parent view, fill_parent being deprecated. wrap_content is used when we want the view to occupy only as much space as required by it.

What does Match_parent mean in Android?

match_parent and fill_parent are same property, used to define width or height of a view in full screen horizontally or vertically. These properties are used in android xml files like this. android:layout_width="match_parent" android:layout_height="fill_parent"

What is match parent and wrap content in Android?

FillParent/Match parent: Fill parent is the older version, the updated one is the match parent which takes the entire screen. Wrap Content: Wrap content takes the length of the text and wraps its content. Example: “This is a Wrap Text”. The wrap content starts wrapping from “This” and ends at “text”.


1 Answers

android:width is for setting an exact number of pixels.

android:layout_width can be a dimension, as above, or it can be one of fill_parent, match_parent, or wrap_content.

It is an error to use something other than a dimension for android:width.

like image 166
Darshan Rivka Whittle Avatar answered Sep 29 '22 23:09

Darshan Rivka Whittle