xml - Android Studio (XML):按钮上的垂直线消失了
问题描述
但是,当我插入一行时,我遇到了两个问题:(1)该行填满了整个页面,(2)当我添加elevation=10dp
. 不知何故,即使我放了alignTop=NIV
and ,这条线也不会减小它的大小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>
解决方案
我在我的系统上尝试过,问题是您将按钮封闭在相对布局中。尝试使用方向 = 水平的线性布局封闭。这是对我有用的代码。虽然我只完成了按钮,但希望它也对你有用。
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 的设计:-
推荐阅读
- php - 通过 PHP 访问公司授权后的 SharePoint 文件
- azure - 使用 Azure AD B2C 用户流的“自定义页面内容”时,是否应该选择“页面布局版本”?
- html - 我试图让文本出现在图像的右侧,并且让实际的图像框比目前的更苗条
- android - 试图让一组文本视图保存在共享首选项中
- c - scanf() 在 for 循环中只运行一次
- android - Flutter 中的参数无效
- mysql - 在mysql中为group by语句选择不同的参数?
- reactjs - 如何防止组件过早消失?
- kotlin - 类型不匹配 Kotlin 和 getStringArrayListExtra
- javascript - Webpack - 多个入口点,需要它们之间的捆绑包