15

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>

Shishir Gupta
  • 1,512
  • 2
  • 17
  • 32
HforHisham
  • 1,914
  • 1
  • 22
  • 34
  • Possible duplicate: [Duplicate](http://stackoverflow.com/questions/2713795/what-is-the-difference-between-androidlayout-width-and-androidwidth) – adneal Jun 24 '12 at 23:25

1 Answers1

23

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.

Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
  • but when i delete `android:width` the appearance changes ,, so it has effect – HforHisham Jun 24 '12 at 23:37
  • @HeshamAbouelsoaod Sorry, I didn't realize `RadioButton` was actually a subclass of `TextView`. I've updated my answer. – Darshan Rivka Whittle Jun 24 '12 at 23:44
  • "width added in API level 1 public int width Information about how wide the view wants to be. Can be one of the constants FILL_PARENT (replaced by MATCH_PARENT in API Level 8) or WRAP_CONTENT, or an exact size." https://developer.android.com/reference/android/view/ViewGroup.LayoutParams#attr_android%3alayout_width – Ian Warburton Aug 27 '18 at 12:31