0

我使用此代码来制作此布局。为什么在这个布局中有一些空间?

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_margin="20dp" 
       android:background="@android:color/transparent"> 
    <LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:layout_centerInParent="true" 
      android:background="@drawable/rounded_white_bg"> 
     <EditText 
       android:id="@+id/login" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:background="@drawable/dialog_edittex" 
       android:layout_margin="10dp"/> 
     <EditText 
       android:id="@+id/password" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:layout_margin="10dp" 
       android:background="@drawable/dialog_edittex"/> 
     <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:textColor="@android:color/black" 
       android:text="AAAAAAAAAAAA" 
       android:layout_gravity="center" 
       android:textSize="20sp" 
       /> 
     <ImageView 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:src="@drawable/dialog_button_bg"/> 

    </LinearLayout> 


</RelativeLayout> 

rouded_whiite.bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#ffffff" /> 
    <corners 
      android:radius="20dp"/> 
</shape> 

但我做到这一点时,我有看到这样的结果。正如你所看到的,红色按钮下方有一些余量。我没有设置任何保证金或其他东西,但在那里有一些空间。我应该在这里做什么来获得像第一拳那样精确的结果。

enter image description here

+1

android:layout_margin =“20dp”? –

+0

你有没有试过在你的'LinearLayout'和'RelativeLayout'中设置android:padding =“0dp”? – Fllo

+2

如果你只能使用RelativeLayout来实现它,你为什么要使用嵌套的线性布局? – r4jiv007

回答

1

用途:

android:layout_centerHorizontal="true"

,而不是

android:layout_centerInParent="true"

并从底部边缘......

0
<LinearLayout 
     android:layout_height="wrap_content" 

正是因为如此。从线性布局除去的ImageView和在相对布局设置,并给属性作为alignparent底部和用于线性布局给alignparent顶部和上述图像视图属性,

1

RelativeLayout卸下余量,使你LinearLayout重力android:layout_centerHorizontal="true"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/transparent"> 
<LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/rounded_white_bg"> 
+0

它没有工作兄弟。 ((下面的空间按钮仍然存在。 – pmb

+0

请发布你的'dialog_edittex'文件的代码。 – GrIsHu

0

尝试这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginTop="20dp" 
       android:background="@android:color/transparent"> 
    <LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:background="@drawable/rounded_white_bg"> 
     <EditText 
       android:id="@+id/login" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:background="@drawable/dialog_edittex" 
       android:layout_margin="10dp"/> 
     <EditText 
       android:id="@+id/password" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:layout_margin="10dp" 
       android:background="@drawable/dialog_edittex"/> 
     <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:textColor="@android:color/black" 
       android:text="AAAAAAAAAAAA" 
       android:layout_gravity="center" 
       android:textSize="20sp" 
       /> 
     <ImageView 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:src="@drawable/dialog_button_bg"/> 

    </LinearLayout> 


</RelativeLayout> 
0

如果您使用的ImageView绘制为.PNG或.J pg使用以下可绘制的图片可能会有所帮助。这个保存为backgroung_bg.xml或其他任何东西,你想

<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item > 
    <shape > 
     <corners android:bottomLeftRadius="20dp" 
      android:bottomRightRadius="20dp" 
      android:topLeftRadius="0dp" 
      android:topRightRadius="0dp"/> 
     <solid android:color="#CF4647"/> 
     <padding android:left="5dp" 
      android:top="5dp" 
      android:right="5dp" 
      android:bottom="5dp"/> 
    </shape> 
</item> 

当你申请这个,你会得到下面的警告只是忽略并运行它。如果你需要的渐变类型的颜色问我

图形预览的布局编辑器可能不准确: 不同角落的大小是不Path.addRoundRect支持。 (忽略此会话)

相关问题