Fabii
Fabii

Reputation: 3890

How do I set any layout(width,height) for tv?

I am creating an app that runs on the logitech revue. The UI is displayed on a TV screen.

The layout looks fine when ran using the emulator. But when it is displayed on a tv screen, parts of the content get cut off.

How do I adjust:

so that its fits the screen no matter the size? fill-parent and wrap_content don't seem to solve this issue.

Can you direct me to some resources if possible or provide an example?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <GridView
        android:id="@+id/propGridView"
        android:layout_width="619dp"
        android:layout_height="487dp"
        android:layout_gravity="center_vertical"
        android:numColumns="5"
        android:paddingTop="20dp" >
    </GridView>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="380dp"
        android:layout_height="508dp"
        android:layout_gravity="center"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/frameLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >

            <ImageView
                android:id="@+id/propertyThumbnail"
                android:layout_width="match_parent"
                android:layout_height="280dp"
                android:layout_weight="0.10"
                android:paddingTop="20dp"
                android:src="@drawable/wow" />
        </FrameLayout>

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:paddingTop="5dp"
            android:text="Title"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Description"
            android:textSize="10dp" />
    </LinearLayout>

</LinearLayout>

Upvotes: 1

Views: 446

Answers (2)

dymmeh
dymmeh

Reputation: 22306

Setting fixed values can lead to problems in your views. Ex. if you have one view with 200dip as the width and the other as 400dip and the screen supported width is 500dip you will have things cut off in your view.

Look into using weights for your widths. If you provide one view with a weight of .6 and another as .4 the 1st view will take up 60% of the screen and the other 40%. This will prevent you from pushing other views off of the screen.

I modified your XML to illustrate its use

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <GridView
        android:id="@+id/propGridView"
        android:layout_width="0dip"
        android:layout_weight=".6"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:numColumns="5"
        android:paddingTop="20dp" >
    </GridView>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="0dip"
        android:layout_weight=".4"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/propertyThumbnail"
            android:layout_width="match_parent"
            android:layout_height="280dp"
            android:layout_weight="0.10"
            android:paddingTop="20dp"
            android:src="@drawable/icon" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:paddingTop="5dp"
            android:text="Title"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Description"
            android:textSize="10dp" />
    </LinearLayout>

</LinearLayout>

I removed the FrameLayout that you had since it was essentially useless

Upvotes: 2

Bondax
Bondax

Reputation: 3163

This should do the trick:

android:layout_width="MATCH_PARENT"
android:layout_height="MATCH_PARENT"

Re-check your complete layout for view parents that have layout params set to "WRAP_CONTENT". These will screw up your layouting.

Upvotes: 0

Related Questions