I have Some layout Problem regarding my Application.
This is My Application Layout:
<?xml version="1.0" encoding="utf-8"?>
<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:src="@drawable/tax_calculator_logo"/>
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" android:layout_gravity="center"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp">
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
</LinearLayout>
Here, I want to set this all button to be complete fit with the height of the Screen of any device.
Yes i can show all the Button. but i want them all to be have equat space between them and they must be fit complete to the Screen height.
So what should i have to do for that ??
Edited:
And there is, My tax_calculator_logo is of 600x239 resolution and i have set the ImageView height as wrap_content and width with fill_parent then why the Image is croping from bottom and top ???
Give equal weight to each of your buttons, they will share height automatically.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<Button
android:id="@+id/contactUs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contact Us"
android:textSize="20dp" />
<Button
android:id="@+id/contactUs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contact Us"
android:textSize="20dp" />
<Button
android:id="@+id/contactUs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contact Us"
android:textSize="20dp" />
<Button
android:id="@+id/contactUs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contact Us"
android:textSize="20dp" />
</LinearLayout>
To do this we have to get he display(screen) width and height.Then through java code assign the height. For exmple
The xml file is like this
<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:src="@drawable/tax_calculator_logo"/>
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" android:layout_gravity="center"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp">
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
<Button android:id="@+id/contactUs" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Contact Us"
android:textSize="20dp"/>
In the Activity class
Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight()/5;
after setContentView(..);
imageview.getLayoutParams().height=height;
button1.getLayoutParams().height=height;
button2.getLayoutParams().height=height;
button3.getLayoutParams().height=height;
button4.getLayoutParams().height=height;
I think this may help you...