Reputation: 633
Right now I have the main screen of my app which has the top 50% of the screen using buttons/content, and the bottom 50% just displaying the logo. However I can't seem to change it so that the logo only takes up the bottom 25% of the screen.
I am using a layout_weight of 3 for the top section, and 1 for the bottom, however this results in the bottom logo now taking up 95% of the screen area and all the content in the main area no longer visible. Using weightSum for the outside container has not worked and neither has playing around with changing layout_width/height to be fill_parent or wrap_content combinations.
I've read other help threads using layout_weight and read the documentation and it all seems very straightforward, and have used them in the content area without issue, I'm not sure why this is giving me trouble here, can anyone help me out?
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textColor="#000000"
android:background="#faff67"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/backing"
android:paddingTop="5dp"
android:paddingRight="3dp"
android:paddingLeft="3dp"
android:paddingBottom="3dp"
android:layout_margin="3dp"
android:layout_weight="3"
>
<!-- Main content area stuff -->
</LinearLayout>
<LinearLayout
android:id="@+id/main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:layout_weight="1"
>
<ImageView android:scaleType="fitCenter"
android:contentDescription="Logo"
android:src="@drawable/logo"
android:id="@+id/front_logo"
android:padding="1sp"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ImageView>
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 1710
Reputation: 8651
Use this
<?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:background="#faff67"
android:orientation="vertical"
android:textColor="#000000" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#123123"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3" >
<ImageView
android:id="@+id/front_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="Logo"
android:padding="1sp"
android:scaleType="fitCenter"
android:src="@drawable/logo" >
</ImageView>
</LinearLayout>
</LinearLayout>
Upvotes: 0
Reputation: 11191
You are using the weight attribute incorrectly. Whenever you set the weight parameter you should set the corresponding width or height to 0dp. Therefore change the height of your layouts in which you assign weight to 0dp.
android:layout_height="0dp"
Upvotes: 0
Reputation: 22342
When using android:layout_weight
, you should set android:layout_height="0dp"
for the weighted components. Otherwise, the layout height will trump the weights in some cases.
Of course, that's for a vertical layout. For horizontal, use android:layout_width="0dp"
Upvotes: 2