【发布时间】: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