Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓在屏幕下方1/4处放置一个按钮_Android_Xml_Button - Fatal编程技术网

Android 安卓在屏幕下方1/4处放置一个按钮

Android 安卓在屏幕下方1/4处放置一个按钮,android,xml,button,Android,Xml,Button,假设黄线是中心线,黑线是黄线和顶部之间的中点。红色框表示我要放置按钮的位置。我不知道如何定义这些位置或使按钮位于它们的中心,而不是位于它们的上方或下方。我更喜欢用xml而不是java来实现,但如果需要的话,我会这样做。也许这和安卓系统有关:体重。感谢诸如此类(省略详细属性): 编辑 因为显然没有人会这么做: <LinearLayout android:orientation="vertical" android:layout_width="match

假设黄线是中心线,黑线是黄线和顶部之间的中点。红色框表示我要放置按钮的位置。我不知道如何定义这些位置或使按钮位于它们的中心,而不是位于它们的上方或下方。我更喜欢用xml而不是java来实现,但如果需要的话,我会这样做。也许这和安卓系统有关:体重。感谢诸如此类(省略详细属性):


编辑 因为显然没有人会这么做:

<LinearLayout 
        android:orientation="vertical" 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    <Button ... />
    <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2" />
    <Button ... />
    <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
</LinearLayout>

向按钮添加必要的属性,应该就是这样。

类似的内容(省略详细属性):


编辑 因为显然没有人会这么做:

<LinearLayout 
        android:orientation="vertical" 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    <Button ... />
    <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2" />
    <Button ... />
    <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
</LinearLayout>


向按钮添加必要的属性,应该就是这样。

我已经测试了这个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">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button1"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" /> 
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button2"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>
</LinearLayout>

我已经测试了这个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">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button1"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" /> 
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button2"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>
</LinearLayout>



为什么嵌套级别这么高?这真是个糟糕的设计。只需在根线性布局中放置两个按钮…是的,我现在做了一个更改,现在查看我编辑的答案@DerGolem@DerGolem:的确如此。一些带有权重的间隔视图就可以了。你为什么不把它写下来作为一个答案(显然这是阿普尔瓦唯一相信它的方式)?(不管怎样,这个额外的嵌套级别增加了一点可读性,imho,我不认为这是一个糟糕的设计)@DerGolem:你说的
百分比
是指
比例
@Apurva:njzk2完全理解了我的想法。好吧,
我可能有点固定了
,但我总是试图让最平坦的设计成为可能。为什么嵌套级别这么高?这真是个糟糕的设计。只需在根线性布局中放置两个按钮…是的,我现在做了一个更改,现在查看我编辑的答案@DerGolem@DerGolem:的确如此。一些带有权重的间隔视图就可以了。你为什么不把它写下来作为一个答案(显然这是阿普尔瓦唯一相信它的方式)?(不管怎样,这个额外的嵌套级别增加了一点可读性,imho,我不认为这是一个糟糕的设计)@DerGolem:你说的
百分比
是指
比例
@Apurva:njzk2完全理解了我的想法。好吧,
我可能有点固定了
,但我总是尽量让最扁平的设计成为可能。我想你可以摆脱RelativeLayouts。
centerInParent
只在RelativeLayout内部工作。它可能被重力的良好利用所取代。@DerGolem:这个解决方案唯一的问题是它要求按钮的高度完全相同。(对于RelativeLayout解决方案,情况并非如此)是的!太好了,@njzk2。这是我心目中最平坦的设计。@DerGolem:flat很好,但我发现RelativeLayout选项做得更好,它将屏幕分为两半,每个屏幕的中心都有一个按钮。我想你可以去掉RelativeLayouts。
centerInParent
只在RelativeLayout内部工作。它可能被重力的良好利用所取代。@DerGolem:这个解决方案唯一的问题是它要求按钮的高度完全相同。(对于RelativeLayout解决方案,情况并非如此)是的!太好了,@njzk2。这是我心目中最平坦的设计。@DerGolem:flat很好,但我发现RelativeLayout选项做得更好,它将屏幕分成两半,每个屏幕的中心都有一个按钮。我刚刚对答案做了一个更改。我删除了不必要的
LinearLayout
代码仍然可以正常工作。检查我编辑的答案,如果它对你有帮助,你可以接受答案。我刚刚对我的答案做了更改。我删除了不必要的
LinearLayout
代码仍然可以正常工作。检查我编辑的答案,如果它对您有帮助,您可以接受答案。