首页 > 解决方案 > Android Studio (XML):按钮上的垂直线消失了

问题描述

我正在尝试在两个按钮之间插入一条小线,如下所示: 在此处输入图像描述

但是,当我插入一行时,我遇到了两个问题:(1)该行填满了整个页面,(2)当我添加elevation=10dp. 不知何故,即使我放了alignTop=NIVand ,这条线也不会减小它的大小alignBottom=NIV

消失线

我该如何解决这些问题?

以防万一您觉得它有用,我的 XML 文件在这里:

<?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:background="@color/colorPrimary"
    android:orientation="vertical"
    android:id="@+id/bibile_xml">

    <TextView
        android:id="@+id/white_background_round"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="50dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="50dp"
        android:background="@drawable/white_background_round" />

    <RelativeLayout
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/white_background_round"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp">

        <TextView
            android:id="@+id/title_string"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title_string"
            android:textColor="@color/colorPrimary"
            android:textSize="50sp"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/title_image"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_toEndOf="@+id/title_string"
            android:layout_marginLeft="20dp"
            android:background="@drawable/ic_bible_english" />
    </RelativeLayout>


    <RelativeLayout
        android:id="@+id/bible_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/title"
        android:layout_centerHorizontal="true">

        <Button
            android:id="@id/KJV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:text="KJV"
            android:textColor="@color/colorPrimaryLight"/>

        <View
            android:layout_width="1dp"
            android:layout_alignEnd="@+id/KJV"
            android:layout_alignParentBottom="true"
            android:background="@android:color/black" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@+id/KJV"
            android:background="@color/colorAccent"
            android:text="NIV"
            android:textColor="@color/colorPrimaryLight" />

    </RelativeLayout>



</RelativeLayout>

标签: xmlandroid-studiobuttonline

解决方案


我在我的系统上尝试过,问题是您将按钮封闭在相对布局中。尝试使用方向 = 水平的线性布局封闭。这是对我有用的代码。虽然我只完成了按钮,但希望它也对你有用。

XML 文件:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:text="KJV"
            android:textColor="@color/colorPrimary"/>

        <View
            android:layout_width="1dp"
            android:layout_alignParentBottom="true"
            android:background="@android:color/black" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:text="NIV"
            android:textColor="@color/colorPrimaryDark" />

</LinearLayout>

这是这个 XML 的设计:-

在此处输入图像描述


推荐阅读