繁体   English   中英

将按钮放在屏幕的左上角

[英]putting button in top left corner of screen

我是Android Studios的新手,很抱歉,如果这是一个愚蠢的问题。 我试图在屏幕顶部放置两个按钮。 我希望它们位于此图像的左上角和右上角。

屏幕顶部按钮

但是,这是他们的样子。

实际按钮布局

我不希望屏幕顶部和两个按钮之间有任何空格。 这是我的代码。

<LinearLayout

        android:layout_marginTop="0dp"
        android:id="@+id/LinearLayout02"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">


    <ImageButton

        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:id="@+id/settingsBTN"
        android:layout_weight="1"
        android:src="@drawable/HomeBTNunpressed"/>

        <View android:layout_width="3dp"
            android:layout_height="50dp"
            android:background="@android:color/black"/>

        <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:id="@+id/homeBTN"
        android:layout_weight="1"
       android:src="@drawable/settingsBTNunpressed"/>

    </LinearLayout>

首先,在父级中不要使用fillParent(Deprecated)而是使用MatchParent。

其次,如果使用线性布局并为视图指定权重,并且您想平等地分配空间,则将宽度0dp和权重1都指定为权重和2。

第三,使用任何包含ImageView的布局为中心,并根据需要指定背景颜色

您正在使用“图像按钮”,并且图像的宽高比被调整为大小,因此不合适。

实际上,您使用的是Image Button,因此边框实际上是按钮。您可以使用Image View并使它在您的代码中可单击而不是使用image button。我在这里使用了自己的Image,但是您可以在xml中使用自己的Image。

 <LinearLayout
  android:id="@+id/LinearLayout02"
  android:layout_height="match_parent"
  android:layout_width="match_parent"
  android:orientation="horizontal"
  xmlns:android="http://schemas.android.com/apk/res/android">


  <ImageView

    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/settingsBTN"
    android:layout_weight=".5"
    android:layout_marginTop="0dp"
    android:background="#B6B6B6"
    android:src="@drawable/username_icon"/>


 <View android:layout_width="3dp"
    android:layout_height="50dp"
    android:background="@android:color/black"/>

  <ImageView

    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_weight=".5"
    android:layout_marginTop="0dp"
    android:background="#B6B6B6"
    android:src="@drawable/username_icon"/>

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM