开发者

layout problem raise

开发者 https://www.devze.com 2023-03-24 04:22 出处:网络
This is my layout file is:: <?xml version=\"1.0\" encoding=\"utf-8\"?> <RelativeLayout android:id=\"@+id/relativeLayout1\"

This is my layout file is ::

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout android:id="@+id/relativeLayout1"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/bg1"
>
<!--    <RelativeLayout android:id="@+id/relativeLayo"
    android:layout_width="480dp" android:layout_height="320dp"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_marginLeft="20dp"
    android:background="@drawable/bg1"> -->



        <ImageView android:src="@drawable/lets_play"
            android:layout_width="wrap_content" android:layout_marginLeft="260dp"
            android:id="@+id/imageView1" android:layout_height="wrap_content"
            android:layout_marginTop="40dp"

            ></ImageView>


    <ImageView android:src="@drawable/show_me"
            android:layout_width="wrap_content" android:layout_marginLeft="220dp"
            android:id="@+id/imageView1" android:layout_height="wrap_content"
            android:layout_marginTop="60dp"

            ></ImageView>

        <ImageButton android:id="@+id/anim_btn_play"
            android:layout_width="wrap_content" android:layout开发者_高级运维_height="wrap_content"
            android:layout_marginLeft="260dp" android:layout_marginTop="150dp"
            android:src="@drawable/play">
        </ImageButton>
</RelativeLayout>

And mobile output is like ::

![this][1]

now my problem is :: i would like to set 480 * 320 size screen and layout is starting from left. At right side there is black portion remain.i have approx ten activity and all activity are going to display same direction. now i would like to show in center like :: ![this][2]

so can you tell me solution?


Easiest method is to wrap your Relative layout with something else, probably linear layout would be fine, and then:

<linearlayout gravity=center>
    <relativelayout width=480dp height=320dp>
    ...

It should quick fix your problem on particular 480x320 screen.

BUT, I would suggest you rethink about your background image to make it possible to adopt to screens with different aspect ratio, consider looking nine-patch and make the background 'strecthable' or make a custom drawable that will stay in middle of screen.

0

精彩评论

暂无评论...
验证码 换一张
取 消