android - 相对布局中的 layout_below 不会显示
问题描述
我正在尝试在相对布局中的 cardview 下创建一个 layout_below,但它不会显示在我的 layout_above 工作设备中。我不知道为什么它不起作用。我认为它应该可以工作,因为它低于卡片视图。请帮助我错过了什么或错了什么。
这是我的 xml 代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_2"
tools:context=".ExchangeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/saldo"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/holder" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Will Stitch"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.CardView
android:id="@+id/saldo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Saldo"
android:textColor="@color/colorPrimary"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/saldo"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch@gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
请帮助为什么会这样
解决方案
它正在工作,但是您ImageView
占用了所有宽度并且它没有android:src
属性(因此它什么都不显示)并且您不需要最后一个 LinearLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/saldo"
android:orientation="vertical">
<!-- Useless Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch@gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
推荐阅读
- javascript - Is it possible to set a cookie to expiry at the end of session and after 1 day?
- security - 如何在 Airflow 2.0 中设置 LDAP 身份验证
- sql-server - SQL Server 跨数据库复制数据
- json - 401 Error when creating file using SFTP Logic App Action
- python - How to put several elements column wise- not douplicated
- orm - RepoDb - Extract function throws exception when using ExecuteQueryMultiple
- machine-learning - 将包添加到 Spacy 管道时出现错误
- node.js - EC2 冻结安装 NodeJS 包 NPM/Yarn - AWS
- javascript - 如何使用 Python 从按钮中抓取隐藏的超链接?
- python - Python随机方形运动不起作用