1 android position bounds android-studio
我正在尝试将按钮位置设置到屏幕的右下角。我尝试过这个:
button.setX(maxX);
button.setY(maxY);
Run Code Online (Sandbox Code Playgroud)
但该按钮是不可见的,因为它不在屏幕上。
编辑:澄清一下。maxX当我将按钮的位置设置为和时,我需要找到一种方法将按钮保留在布局内maxY。以免其越界。因此,即使我将其位置设置为:
button.setX(maxX - 10);
button.setY(maxY - 10);
Run Code Online (Sandbox Code Playgroud)
它不会有一半伸出屏幕。
请检查此SO答案更改按钮的位置。
另一种方法,您可以将其添加到按钮中(RelativeLayout)
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
Run Code Online (Sandbox Code Playgroud)
示例演示
<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"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#AF3800"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
Run Code Online (Sandbox Code Playgroud)
android:layout_alignParentBottom
如果为 true,则使该视图的下边缘与父视图的下边缘匹配。容纳底部边距。
android:layout_alignParentRight如果为 true,则使该视图的右边缘与父视图的右边缘匹配。容纳右边距。
两者都是布尔值,要么是“true”,要么是“false”。
我希望它能帮助你。
| 归档时间: |
|
| 查看次数: |
66218 次 |
| 最近记录: |