更改Android Studio屏幕大小的按钮大小
由于dpi,此时按钮/编辑文本和输出都与屏幕大小有关 我该如何调整它以适应不同的屏幕尺寸?由于这是目前发生的情况: 这是理想的:更改Android Studio屏幕大小的按钮大小,android,xml,android-studio,layout,screen-size,Android,Xml,Android Studio,Layout,Screen Size,由于dpi,此时按钮/编辑文本和输出都与屏幕大小有关 我该如何调整它以适应不同的屏幕尺寸?由于这是目前发生的情况: 这是理想的: 这不是:您将使用hdpi、xhdpi等文件夹() 干杯您将使用hdpi、xhdpi等文件夹() 干杯试试这个布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
这不是:您将使用hdpi、xhdpi等文件夹()
干杯您将使用hdpi、xhdpi等文件夹()
干杯试试这个布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/resultOutput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:password="false"
android:phoneNumber="false"
android:text="0"
android:textAlignment="center"
android:textIsSelectable="true"
android:textSize="30dp" />
<GridLayout
android:id="@+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/resultOutput"
android:layout_marginBottom="50dp">
<EditText
android:id="@+id/x1"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:ems="10"
android:focusable="true"
android:hint="x1"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/x2" />
<EditText
android:id="@+id/x2"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:ems="10"
android:focusable="true"
android:hint="x2"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/x3" />
<EditText
android:id="@+id/x3"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="0"
android:ems="10"
android:focusable="true"
android:hint="x3"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/y1" />
<EditText
android:id="@+id/y1"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:ems="10"
android:focusable="true"
android:hint="y1"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/y2" />
<EditText
android:id="@+id/y2"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:ems="10"
android:focusable="true"
android:hint="y2"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/y3" />
<EditText
android:id="@+id/y3"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="1"
android:ems="10"
android:focusable="true"
android:hint="y3"
android:inputType="number|numberDecimal" />
</GridLayout>
<LinearLayout
android:id="@+id/row1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/gridLayout"
android:orientation="horizontal">
<Button
android:id="@+id/addButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:layout_margin="8dp"
android:background="#3F51B5"
android:text="Add"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/subButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Sub"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/unitButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Unit"
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/row1"
android:orientation="horizontal">
<Button
android:id="@+id/crossButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:layout_margin="8dp"
android:background="#3F51B5"
android:text="Cross"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/dotButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Dot"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/magButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Mag"
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
<Button
android:id="@+id/resetButton"
android:layout_below="@id/row2"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center|top"
android:layout_marginTop="10dp"
android:background="#3F51B5"
android:text="Reset"
android:textColor="#ffffff"
android:textSize="25sp" />
</RelativeLayout>
试试这个布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/resultOutput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:password="false"
android:phoneNumber="false"
android:text="0"
android:textAlignment="center"
android:textIsSelectable="true"
android:textSize="30dp" />
<GridLayout
android:id="@+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/resultOutput"
android:layout_marginBottom="50dp">
<EditText
android:id="@+id/x1"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:ems="10"
android:focusable="true"
android:hint="x1"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/x2" />
<EditText
android:id="@+id/x2"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:ems="10"
android:focusable="true"
android:hint="x2"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/x3" />
<EditText
android:id="@+id/x3"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="0"
android:ems="10"
android:focusable="true"
android:hint="x3"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/y1" />
<EditText
android:id="@+id/y1"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:ems="10"
android:focusable="true"
android:hint="y1"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/y2" />
<EditText
android:id="@+id/y2"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:ems="10"
android:focusable="true"
android:hint="y2"
android:inputType="number|numberDecimal"
android:nextFocusDown="@+id/y3" />
<EditText
android:id="@+id/y3"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="1"
android:ems="10"
android:focusable="true"
android:hint="y3"
android:inputType="number|numberDecimal" />
</GridLayout>
<LinearLayout
android:id="@+id/row1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/gridLayout"
android:orientation="horizontal">
<Button
android:id="@+id/addButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:layout_margin="8dp"
android:background="#3F51B5"
android:text="Add"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/subButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Sub"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/unitButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Unit"
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/row1"
android:orientation="horizontal">
<Button
android:id="@+id/crossButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:layout_margin="8dp"
android:background="#3F51B5"
android:text="Cross"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/dotButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Dot"
android:textColor="#ffffff"
android:textSize="25sp" />
<Button
android:id="@+id/magButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Mag"
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
<Button
android:id="@+id/resetButton"
android:layout_below="@id/row2"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center|top"
android:layout_marginTop="10dp"
android:background="#3F51B5"
android:text="Reset"
android:textColor="#ffffff"
android:textSize="25sp" />
</RelativeLayout>
这通常是一个很长的过程: 您必须为每个布局创建单独的目录,以便与用户保持一致: 您必须为每个屏幕大小制作不同的布局,android会根据包含XML文件内容的目录名自动设置布局: 在ANDROID STUIDO中: 现在,选择尺寸: 对您拥有的每个布局执行此操作: (现在人们认为小型设备已经过时了) 然后,只需在每个目录中呈现布局。您不必这样创建目录,如果您愿意,您可以进入项目视图并创建它们并复制xml文件,但这种方法要简单得多 如果有帮助,请告诉我
Ruchir这通常是一个很长的过程: 您必须为每个布局创建单独的目录,以便与用户保持一致: 您必须为每个屏幕大小制作不同的布局,android会根据包含XML文件内容的目录名自动设置布局: 在ANDROID STUIDO中: 现在,选择尺寸: 对您拥有的每个布局执行此操作: (现在人们认为小型设备已经过时了) 然后,只需在每个目录中呈现布局。您不必这样创建目录,如果您愿意,您可以进入项目视图并创建它们并复制xml文件,但这种方法要简单得多 如果有帮助,请告诉我
Ruchir自API 21以来,您可以使用android:layout\u columnWeight=“1”为每个元素列分配多余的空间 为了均匀地填充每个列空间,您需要指定相同的列权重 检查GridLayout android参考
部分多余空间分配自API 21以来,您可以使用android:layout\u columnWeight=“1”为每个元素列分配多余空间 为了均匀地填充每个列空间,您需要指定相同的列权重 检查GridLayout android参考
第节多余空间分布我试过了,按钮的位置仍然很奇怪。我在按钮上使用网格布局这一事实是否会成为问题?请看我更新的回答,我用线性布局替换了按钮,并将所有按钮设置为相同的权重。我尝试了这一点,但按钮的位置仍然很奇怪。我在按钮上使用网格布局这一事实会成为问题吗?请参阅我的更新回复,我将按钮替换为线性布局,并为所有按钮设置相同的权重。因此,我是否需要更改各种设备的视觉布局?因为我在一加一和Nexus7上看到了我想要的样子。@Sectah是的,非常感谢。我对我的应用程序所做的是,通过在一个布局中添加更多内容,优化xlarge设备等设备上的开放空间。或者,你可以增加所有东西的大小。如果这有帮助,请按答案左侧的复选标记接受它。如果您需要更多帮助,请随时询问!:)那么,我是否需要改变各种设备的视觉布局?因为我在一加一和Nexus7上看到了我想要的样子。@Sectah是的,非常感谢。我对我的应用程序所做的是,通过在一个布局中添加更多内容,优化xlarge设备等设备上的开放空间。或者,你可以增加所有东西的大小。如果这有帮助,请按答案左侧的复选标记接受它。如果您需要更多帮助,请随时询问!:)