user3516943
user3516943

Reputation: 71

How can you make your android application occupy only half of the screen?

I have a list, but it will occupy all the screen of the tablet. Is there a way to make it only occupy half , or 1/4 of the tablet screen?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:layout_gravity="center_vertical"
        android:layout_weight="1" />

</LinearLayout>

Upvotes: 0

Views: 1129

Answers (2)

ngrashia
ngrashia

Reputation: 9904

You can use the following in your XML for vertical split of screen: Here we are using weightsum and weight attributes. You can adjust the weight property to get the desired results in terms of half or quarter etc.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >

  <RelativeLayout
     android:id="@+id/button1"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="50"
     android:background="@android:color/black" >

     <!-- Your RelativeLayout Items -->

  </RelativeLayout>

</LinearLayout>

In order to get the same in horizontal manner, the below would be useful:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@android:color/darker_gray"
  android:orientation="horizontal"
  android:weightSum="100" >

  <RelativeLayout
    android:id="@+id/button1"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="50"
    android:background="@android:color/black" >

      <!-- Your RelativeLayout Items -->

  </RelativeLayout>

</LinearLayout>

EDIT: To display as widgets, You can refer tutorials here http://www.vogella.com/tutorials/AndroidWidgets/article.html and here http://www.tutorialspoint.com/android/android_widgets.htm

Upvotes: 0

Bipin Bhandari
Bipin Bhandari

Reputation: 2692

Add another blank view or the view that you want to place in another half. Set its layout weight to 0.5: android:layout_weight=".5".

Set android:layout_weight=".5" for ListView.

Note that setting layout_weight to .5, if there is a single view in a container would have no effect.

Good Luck!

Upvotes: 1

Related Questions