屏幕底部的白线(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并不是我们可以做到的。 这就像一个解决方法,而不是一个合适的解决方案。
链接地址: http://www.djcxy.com/p/93223.html