【问题标题】:How can I design an activity with this apparence which work on any device with any resolution我如何设计具有此外观的活动,该活动可在任何分辨率的任何设备上运行
【发布时间】:2016-03-30 17:54:34
【问题描述】:

我想设计一个可以在任何屏幕分辨率的任何设备上运行的软件。 你能帮我吗? 我使用了 android:layout_weight 但它让我发疯了

如果您有任何其他建议,请告诉我。

这是 XML 代码,但太长了。

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".TTT">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/Titre2"
            android:id="@+id/txtTitre2"
            android:layout_alignParentStart="false"
            android:layout_alignParentTop="false"
            android:layout_alignParentBottom="false"
            android:layout_alignParentRight="true"
            android:layout_alignParentLeft="true"
            android:gravity="center"
            android:textColor="#000000"
            android:textStyle="bold"
            android:textSize="16sp"
            android:textIsSelectable="false"
            android:layout_weight="1" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/textView"
            android:layout_below="@+id/txtTitre2"
            android:textSize="16sp"
            android:layout_weight="1" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B0"
                        android:layout_row="0"
                        android:layout_column="0"
                        android:layout_weight="1"/>

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B1"
                        android:layout_row="0"
                        android:layout_column="1"
                        android:layout_weight="1"/>

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B2"
                        android:layout_row="0"
                        android:layout_column="2"
                        android:layout_weight="1"/>
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B3"
                        android:layout_row="1"
                        android:layout_column="0"
                        android:layout_weight="1"/>

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B4"
                        android:layout_row="1"
                        android:layout_column="1"
                        android:layout_weight="1"/>

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B5"
                        android:layout_row="1"
                        android:layout_column="2"
                        android:layout_weight="1"/>
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B6"
                        android:layout_row="2"
                        android:layout_column="0"
                        android:layout_weight="1"/>

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B7"
                        android:layout_row="2"
                        android:layout_column="1"
                        android:layout_weight="1"/>

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/B8"
                        android:layout_row="2"
                        android:layout_column="2"
                        android:layout_weight="1"/>
                </LinearLayout>

            </LinearLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Small Text"
                android:id="@+id/textView5"
                android:layout_weight="2"/>

        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:id="@+id/textView7"
            android:text="12121212"
            android:layout_weight="1" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Small Text"
                android:id="@+id/textView6" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="@string/New"
                android:id="@+id/button"
                android:layout_row="4"
                android:layout_column="2"
                android:onClick="newGame" />
        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Small Text"
            android:id="@+id/textView8"
            android:layout_weight="3" />

    </LinearLayout>

</RelativeLayout>

【问题讨论】:

    标签: android-layout android-activity android-widget android-linearlayout screen-resolution


    【解决方案1】:

    我解决了。 当我们使用 android:layout_weight=Value 时,如果我们使用 vertical linearlayout,我们应该将 android:layout_weight 的值设置为 0dp强>和
    如果我们使用 horizo​​ntal linearlayout,我们应该将 android:layout_height 的值设置为 0dp
    顶部六个布局的值应分别为 1, 1, 3, 1, 1 ,3。
    为了在第 5 个布局中与左侧有 40% 的距离,我们应该将其定义为垂直线性布局,并将第一个为空的 TextView 的权重设置为 2 和按钮 3,最后一个为 Empty TextView 1

    我放了必要的 XML 代码

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3">
        </LinearLayout>
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2" />
    
            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2" />
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
        </LinearLayout>
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3" />
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-21
      • 2013-10-23
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多