繁体   English   中英

屏幕底部的白线(LinearLayout)

[英]White line at the bottom of the screen (LinearLayout)

我正在为我的应用程序登录屏幕。 问题是我在每台设备和模拟器上的屏幕底部都出现一条白线。 您可以在此处检查输出: http : //www.imgur.com/cTMu4Ap这是我的布局xml代码。 请注意,我正在使用layout_weight属性在所有设备之间分配相等的空间。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:src="@mipmap/ic_launcher"
        android:layout_gravity="center"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingLeft="55dp"
        android:paddingRight="55dp"
        android:background="@color/colorPrimary"
        >
        <EditText
            android:id="@+id/edtEmailOrMobileNumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/email_or_mobile_number"
            android:background="@null"
            android:inputType="textEmailAddress"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white"
            android:drawableLeft="@drawable/ic_clear"

            android:layout_marginTop="64dp"
            />
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            />
        <EditText
            android:id="@+id/edtPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/password"
            android:background="@null"
            android:inputType="textPassword"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white"
            android:drawableLeft="@drawable/ic_clear"
            android:drawableRight="@drawable/ic_clear"

            android:layout_marginBottom="20dp"
            />
        <Button
            android:id="@+id/btnSignIn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/sign_in"
            android:layout_gravity="center"
            android:textColor="@color/blue_login_button"
            android:background="@drawable/rounded_corner_button_login_background"
            android:textAllCaps="false"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="@string/dont_have_an_account"
            android:layout_gravity="center"
            android:gravity="center|bottom"
            android:paddingBottom="30dp"
            android:textColor="@android:color/white"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:orientation="vertical"
        android:gravity="center"
        android:background="@drawable/button_create_account_background"
        android:clickable="true"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/create_an_account"
            android:textColor="@android:color/white"
            />
    </LinearLayout>

</LinearLayout>

哪里出了毛病

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.2"
    android:orientation="vertical"
    android:gravity="center"
    android:background="@drawable/button_create_account_background"
    android:clickable="true"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/create_an_account"
        android:textColor="@android:color/white"
        />
</LinearLayout>

实际上,您的最后一个布局不是purely底面的。这就是为什么有问题。另一个问题android:layout_weight="0.2" 。android :layout_weight不适合设置底面。

尝试这个

我认为您应该尝试相对布局。如果您有一个相对布局可以覆盖整个屏幕,则应该可以使用android:layout_alignParentBottom将按钮移至屏幕底部。 礼貌

要么

您可以使用LinearLayout android:weightSum属性。

android中的android:weightSum是什么,它如何工作?

我发现解决1dp线问题的最简单方法是按比例放大您用于权重的值。

一种简单的方法是按比例缩放每个权重,直到没有小数点为止,例如:

android:layout_weight="0.2"

会成为

android:layout_weight"2"

如果您将此乘数应用于布局中的每个权重,则它们都应保持相同的比例,但底部没有线条。

我不能肯定地说,但是我的假设是,使用较小的十进制值会导致Android出现舍入错误-在布局的底部保留不需要的1dp行。

我遇到了同样的问题,将LinearLayout的android:layout_height="match_parent"更改为android:layout_height="fill_parent"解决了该问题。

在我的应用程序中,白色边框仅显示在一个“幻灯片”上。 我不确定,但是我认为我们显示的图像会对此产生影响。

当然,改变layout_height并不是我们总能做的。 这就像是一种变通方法,而不是适当的解决方案。

暂无
暂无

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

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