Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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布局中使用xml的全宽按钮_Android_Xml - Fatal编程技术网

android布局中使用xml的全宽按钮

android布局中使用xml的全宽按钮,android,xml,Android,Xml,我想使用xml在android中创建全宽按钮。 这是我的密码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android

我想使用xml在android中创建全宽按钮。 这是我的密码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/menu"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:src="@drawable/manulogo" />
    <Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@android:drawable/btn_star_big_on"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="220dp"
    android:text="Drawable left" 
    />
</RelativeLayout>

您必须这样做

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
父布局具有左右填充,因此将其删除,按钮将全屏显示

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@drawable/menu"
   android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context=".MainActivity" >

     <ImageView
        android:id="@+id/imageView2"
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:src="@drawable/manulogo" />
      <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawableLeft="@android:drawable/btn_star_big_on"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="220dp"
        android:text="Drawable left" 
      />
</RelativeLayout>

如果您想去掉左右两侧的16 dp边距,则需要从主相对布局中删除填充属性

此外,不能将属性
方向
与相对布局一起使用。这是线性布局

您应该使用
match\u parent
而不是
fill\u parent
进行更好的练习:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/menu"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:src="@drawable/ic_launcher" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="220dp"
        android:drawableLeft="@android:drawable/btn_star_big_on"
        android:text="Drawable left" />

</RelativeLayout>

这段修改过的代码运行良好

输出:


向我们展示完整的布局。并指定您面临的问题。在布局按钮已满屏的情况下,请澄清问题。尝试从父布局中删除左右填充。您可以在本文[如何在按钮内设置图像和文本中心][1][1]中找到答案:首先,我回答了这个问题,用户也接受了我的答案,他不接受我的答案的原因是什么,我不知道,现在一些好友记下了,你能解释为什么吗???我的答案被否决了?