我已经创建了一个xml文件。但问题是,当移动设备的屏幕尺寸发生变化时,设计会有一些变化。我已经搜索但仍然困惑。我想要的是,这样做是为了让每个设计保持相同移动,不能依赖于它的屏幕大小。以下是我的xml文件 -
player.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="6"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#fff">
<Button
android:layout_width="70dp"
android:layout_height="45dp"
android:background="@drawable/backbtn"
android:textSize="19dp"
android:id="@+id/back"
/>
<TextView
android:layout_width="335dp"
android:layout_height="45dp"
android:text="Welcome"
android:textSize="30dp"
android:background="#fff"
android:textColor="#000"
android:layout_marginRight="40dp"
android:paddingRight="40dp"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/textView3" />
<TextView
android:layout_width="20dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_marginStart="10dp"
android:id="@+id/id"
android:layout_marginLeft="100dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="@+id/plname"
android:text="ABC XYZ"
android:layout_gravity="center"
android:layout_weight="1"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#fff"
android:paddingLeft="5dp"
android:background="#7ee77c"
android:gravity="left|center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="@+id/plid"
android:layout_toRightOf="@+id/plname"
android:layout_weight="1"
android:text="Player ID:"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#fff"
android:paddingLeft="10dp"
android:layout_gravity="center"
android:gravity="right|center"
android:background="#7ee77c"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="1"
android:id="@+id/plidtxt"
android:text="1000"
android:textColor="#fff"
android:background="#7ee77c"
android:textSize="20dp"
android:paddingTop="2dp"
android:textStyle="bold"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:gravity="left|center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
>
<TextView
android:layout_width="170dp"
android:layout_height="29dp"
android:id="@+id/day"
android:layout_below="@id/line2"
android:text="Wednesday"
android:textStyle="bold"
android:textSize="20dp"
android:gravity="right|center"
android:textColor="#000"
android:paddingRight="10dp"
android:background="@android:color/transparent"
/>
<TextView
android:layout_width="115dp"
android:layout_height="29dp"
android:id="@+id/date"
android:layout_below="@+id/line2"
android:layout_toRightOf="@id/day"
android:text="05/04/2017"
android:textStyle="bold"
android:textSize="20dp"
android:gravity="left|center"
android:textColor="#000"
android:paddingLeft="3dp"
android:background="@android:color/transparent"
/>
<TextView
android:layout_width="95dp"
android:layout_height="29dp"
android:id="@+id/time"
android:layout_below="@id/line3"
android:layout_toRightOf="@+id/date"
android:text="12.00"
android:textColor="#000"
android:textSize="20dp"
android:paddingBottom="4dp"
android:background="@android:color/transparent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp"
>
<SearchView
android:layout_width="290dp"
android:layout_height="45dp"
android:id="@+id/search"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:queryHint="Search"
android:layout_gravity="center_horizontal"
android:layout_below="@+id/day"
android:layout_centerHorizontal="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
>
<TextView
android:layout_width="40dp"
android:layout_height="match_parent"
android:text="Sr"
android:id="@+id/sr"
android:paddingTop="5dp"
android:textSize="20dp"
android:layout_marginTop="7dp"
android:textStyle="bold"
android:textColor="#fff"
android:background="#b27ce7"
android:gravity="center"
/>
<TextView
android:layout_width="145dp"
android:layout_height="match_parent"
android:text="Player Name"
android:layout_toRightOf="@+id/sr"
android:id="@+id/player"
android:paddingTop="5dp"
android:layout_weight="1"
android:textSize="20dp"
android:layout_marginTop="7dp"
android:textStyle="bold"
android:textColor="#fff"
android:background="#b27ce7"
android:gravity="center"
/>
<TextView
android:layout_width="28dp"
android:layout_height="match_parent"
android:id="@+id/a"
android:layout_weight="0.12"
android:layout_marginTop="7dp"
android:layout_toRightOf="@+id/player"
android:background="#b27ce7"
/>
<TextView
android:layout_width="40dp"
android:layout_height="43dp"
android:layout_toRightOf="@+id/a"
android:id="@+id/rank"
android:text="Rank"
android:layout_marginTop="7dp"
android:textSize="20dp"
android:textStyle="bold"
android:paddingBottom="1dp"
android:textColor="#fff"
android:gravity="center"
android:background="#b27ce7"
android:layout_weight="1" />
<TextView
android:layout_width="27dp"
android:layout_height="match_parent"
android:id="@+id/b"
android:layout_weight="0.12"
android:layout_marginTop="7dp"
android:layout_marginBottom="1dp"
android:layout_toRightOf="@+id/rank"
android:background="#b27ce7"
/>
<TextView
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="#b27ce7"
android:layout_marginTop="7dp"
android:text="Team"
android:paddingTop="5dp"
android:layout_toRightOf="@+id/b"
android:textStyle="bold"
android:textColor="#fff"
android:textSize="20dp"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ListView
android:layout_width="330dp"
android:layout_height="250dp"
android:id="@+id/pllist"
android:background="#ffff"
android:layout_weight="1"
android:scrollbars="vertical"
android:divider="@null"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:dividerHeight="0dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:layout_below="@+id/listline1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:layout_width="match_parent"
android:layout_height="42dp"
android:id="@+id/update"
android:background="#4e57a9"
android:text="Update"
android:textColor="#000"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:textAllCaps="false"
android:layout_above="@+id/delete"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_alignParentBottom="true"
android:id="@+id/delete"
android:layout_centerHorizontal="true"
android:background="#4e57a9"
android:text="Delete"
android:textColor="#000"
android:layout_marginBottom="15dp"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textAllCaps="false"
/>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
我认为你必须定义主线性布局的高度和宽度。 喜欢这个
clojure-1.9.0-alpha15
答案 1 :(得分:0)
幸运的是,这很容易做到,因为android主要是为你处理它。您只需为要支持的每种不同屏幕尺寸制作不同的布局文件。
重要的部分是将它们命名为相同(example.xml
),但是将它们放在具有某些标记的不同文件夹中,这些标记在应该使用时标识到android。例如res/values/example.xml
vs res/values-sw600dp-land/example.xml
其中sw600dp和land是用于确定最小宽度和横向方向的限定符。你可以在这里读更多关于它的内容。 https://developer.android.com/training/multiscreen/screensizes.html
答案 2 :(得分:0)
不为widget.use layout_weight属性分配固定的高度和宽度,并设置所有小部件。
否则使用
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra-large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra-large in landscape orientation
res/drawable-mdpi/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
res/mipmap-mdpi/my_icon.png // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png // launcher icon for extra-extra-extra-high-density