android - 线性和相对布局
问题描述
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
tools:context=".MainActivity"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/androidparty" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DEALS IN:-"
android:padding="10dp"/>
</LinearLayout>
</RelativeLayout>
在相对布局中,当我将高度和重量设置为 match_parent 时,我的文本滑到设计面板的底部并且不可见,为什么会发生这种情况?
解决方案
您必须指定视图在RelativeLayout
.
您可以查看文档:
每个视图的位置可以指定为相对于同级元素(例如在另一个视图的左侧或下方)或相对于父
RelativeLayout
区域的位置(例如与底部、左侧或中心对齐)。
例如使用android:layout_alignParentTop="true"
:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DEALS IN:-"
android:padding="10dp"/>
</RelativeLayout>
在您的布局中还有另一个问题:
<LinearLayout
android:orientation="vertical">
<RelativeLayout
android:layout_height="match_parent"/>
<TextView/>
</LinearLayout>
RelativeLayout
has并以这种android:layout_height="match_parent"
方式填充父视图,TextView
而RelativeLayout
.
推荐阅读
- vb.net - vb.net - 如果没有可读取的内容,StreamReader 将挂起
- vagrant - 宅基地不加载网页
- c# - 根据当前 CultureInfo ASP.NET Core 存储 DateTime
- powershell - 选择 x 数量的文件并将它们复制到另一个文件夹的批处理文件
- ios - 子视图关闭后父视图不刷新
- java - 需要从 List 中的每个文件中读取每 N 行
- vue.js - 创建一个新的 vue-moveable 实例
- python - 如何始终在 Python 中导入一组模块
- swift - 虽然当前导航然后显示视图控制器栏按钮不来,为什么在 swift
- javascript - 在我的表单按钮上调用 submit() 和 reload() 不起作用