如何使动态线性布局与五个图像视图与它



你好,我已经做了两天了。

基本上我想实现这个设计(请见红色圈出的那个):

http://tinypic.com/r/dy52k0/8

我希望我的xml布局为这个是动态的,无论手机的屏幕大小,它将只是扩大或缩小(简而言之,它将保留设计)。

不幸的是,我现在有一段艰难的时间。这是我的代码的结果:

http://tinypic.com/r/29uo8d4/8

下面是我的代码:
    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
        <!-- start - Main Buttons for Main Pages -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            <!-- start - For Glomp Image -->
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="#585f6b"
                android:gravity="center"
                android:paddingLeft="10sp"
                android:paddingRight="10sp" >
                <ImageView
                    android:layout_width="170sp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20sp"
                    android:layout_marginRight="20sp"
                    android:src="@drawable/glomp_logo_for_login" />
            </RelativeLayout>
            <!-- end - For Glomp Image -->

            <!-- start - For 4 Menu Buttons -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="0sp" >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                    <ImageView
                        android:id="@+id/imgV_main_menu_points"
                        android:layout_width="80sp"
                        android:layout_height="80sp"
                        android:layout_weight="1"
                        android:src="@drawable/glomped" />
                    <ImageView
                        android:id="@+id/imgV_main_menu_glomped"
                        android:layout_width="80sp"
                        android:layout_height="80sp"
                        android:layout_weight="1"
                        android:src="@drawable/friends" />
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                    <ImageView
                        android:id="@+id/imgV_main_menu_points"
                        android:layout_width="80sp"
                        android:layout_height="80sp"
                        android:layout_weight="1"
                        android:src="@drawable/menu" />
                    <ImageView
                        android:id="@+id/imgV_main_menu_points"
                        android:layout_width="80sp"
                        android:layout_height="80sp"
                        android:layout_weight="1"
                        android:src="@drawable/points" />
                </LinearLayout>
            </LinearLayout>
            <!-- end - For 4 Menu Buttons -->
        </LinearLayout>
        <!-- end - Main Buttons for Main Pages -->
    </LinearLayout>
</ScrollView>

我非常感谢你的帮助。

Thanks to lot

对于动态布局,您的imageviews需要将宽度设置为android:layout_width="wrap_content",而不是像您所做的那样以单位为单位。

您将需要不同尺寸的图像来支持不同的屏幕尺寸和分辨率,并将它们放置在res/drawable中的特定文件夹中,如-

MyProject/res/
drawable-xhdpi/
    awesomeimage.png
drawable-hdpi/
    awesomeimage.png
drawable-mdpi/
    awesomeimage.png
drawable-ldpi/
    awesomeimage.png

你也可以有不同的rs/layout文件夹。

请参见:支持多屏幕

我希望它会对你有帮助,因为刚刚创建了相同的视图。我将为所有设备工作

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF00FF" >
<!-- this is glomp -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" >
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#FFFF00"
        android:orientation="vertical" >
        <!-- this is glomp G -->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#31B404" />
         <!-- this is menu-->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#2A120A" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#FFFFFF"
        android:orientation="vertical" >
         <!-- this is friends-->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#00FF00" />
         <!-- this is point-->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000000" />
    </LinearLayout>
  </LinearLayout>
  </LinearLayout>

最新更新