我应该从layout_weight移动探底? [英] should I move from layout_weight to dip?

查看:130
本文介绍了我应该从layout_weight移动探底?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小部件。我故意用 layout_weight

I have created a widget. I intentionally used layout_weight

所以它适合任何屏幕尺寸。

so it would fit any screen size.

小部件总是跨越到1X4。

The widget is always spanned to 1X4.

我现在看在不同设备中的图形编辑器,我看到的重量并没有帮助。

I now look at different devices in the graphic editor and I see the weight doesn't help.

我应该搬到沾大小?

的线性布局相对于背景图象不同跨区

The linear-layouts are spanned differently in relation to the background image.

我的XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/app_widget_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/widget_bg_main"
    android:clickable="true"
    android:focusable="true"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:padding="0dp" >

    <RelativeLayout
        android:id="@+id/layout_status_image"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="horizontal" 
android:layout_weight="0.21"
>

        <ImageView
            android:id="@+id/image_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/widget_icon_no_data"
            android:visibility="invisible" />
        <!--
                              Layout is necessary because the setVisibility of ProgressBar is not working 
                              through remote views in 2.1. So wrapped by this layout 
        -->

        <FrameLayout
            android:id="@+android:id/widget_progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginLeft="1dp"
            android:layout_marginTop="1dp" >

            <ProgressBar
                style="?android:attr/progressBarStyle"
                android:layout_width="39dp"
                android:layout_height="39dp"
                android:indeterminateOnly="true"
                android:orientation="vertical" />
        </FrameLayout>
    </RelativeLayout> <!-- Status image layout -->


    <!--
                            ========================================================================
                            * Information layout - contains all the texts 
                            ========================================================================
    -->

    <LinearLayout
        android:id="@+id/layout_information"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical" 
        android:paddingLeft="20dp"
        android:layout_weight="0.56"
        >

        <TextView
            android:id="@+id/text_view_destination"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="\@ Home in"
            android:textColor="@color/solid_white"
            android:textSize="19sp"
            android:textStyle="bold" 
            android:layout_gravity="left" 

            />

        <TextView
            android:id="@+id/text_view_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:textColor="@color/solid_white"
            android:textSize="25sp"
            android:textStyle="normal" 
            android:layout_gravity="left"
            />
    </LinearLayout> <!-- Information layout -->
    <!--
                            ========================================================================
                            * Action layout - action buttons container
                            ========================================================================
    -->

    <LinearLayout
        android:id="@+id/layout_action"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="vertical" 
        android:layout_weight="0.23"
        >

        <ImageView
            android:id="@+id/image_action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/widget_bt_drive_disabled" />

        <TextView
            android:id="@+id/text_view_action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:text="Drive!"
            android:textColor="@color/disabled_white"
            android:textSize="15sp"
            android:textStyle="bold" 
            android:layout_gravity="center"
            />
    </LinearLayout> <!-- Action layout -->

推荐答案

这是明显,因为单布局的普通屏幕大小的设备上完美的工作,并不意味着它会工作在大/ XLARGE屏幕尺寸相同的方式。因此,建立内部资源文件夹布局大或布局XLARGE(根据设备屏幕大小)。同样的布局复制到新创建的文件夹,然后作出一些改变它,所以它会适合大/ XLARGE屏幕按您的要求。你也可以复制图像到LDPI,MDPI,华电国际和xhdpi支持多种密度。

It is obvious because single layout working perfectly on a normal screen sized device doesn't mean that it'll work the same way on large/xlarge sized screens. So create a folder inside res "layout-large" or "layout-xlarge" (depending on device screen size). Copy same layout into newly created folder and then make some changes to it, so it'll fit for large/xlarge screens as per your requirement. Also you may copy images into ldpi, mdpi, hdpi and xhdpi to support multiple densities.

欲了解更多信息: http://developer.android.com/guide/practices/ screens_support.html

希望这有助于。

这篇关于我应该从layout_weight移动探底?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆