Android 如何填充RelativeLayout中的空白?
我有一个RelativeLayout作为父布局,它包含两个视图:视频视图和自定义媒体控制器的自定义视图。这两个视图填充了RelativeLayout的一些空间,我想通过LinearLayout填充其余空间,如图所示: 这是我的xml代码:Android 如何填充RelativeLayout中的空白?,android,xml,Android,Xml,我有一个RelativeLayout作为父布局,它包含两个视图:视频视图和自定义媒体控制器的自定义视图。这两个视图填充了RelativeLayout的一些空间,我想通过LinearLayout填充其余空间,如图所示: 这是我的xml代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
<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"
tools:context=".MainActivity"
android:orientation="vertical"
android:id="@+id/relativeLayout">
<VideoView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/videoView"/>
<com.example.arantik.test13.MyMediaController
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/myMediaController"
android:layout_below="@id/videoView"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ff0000"
android:layout_alignParentBottom="true"
android:layout_alignBottom="@id/myMediaController">
</LinearLayout>
</RelativeLayout>
父布局必须是RelativeLayout。我如何做到这一点?将父级布局设置为
线性布局
和
android:orientation=“vertical”
或
如果需要父布局作为相对布局。在
线性布局中添加以下代码
android:layout_below=“@+id/myMediaController”
将您的父布局设置为线性布局
和
android:orientation=“vertical”
或
如果需要父布局作为相对布局
。在线性布局中添加以下代码
android:layout_below=“@+id/myMediaController”
在这种情况下为什么不使用LinearLayout呢
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<com.example.arantik.test13.MyMediaController
android:id="@+id/myMediaController"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff0000"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
更新
如果您想在RelativeLayout中使用此功能,请将android:layout_放在LinearLayout
的下面=“@id/myMediaController”
上,在这种情况下为什么不使用LinearLayout呢
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<com.example.arantik.test13.MyMediaController
android:id="@+id/myMediaController"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff0000"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<VideoView
android:layout_width="match_parent"
android:layout_height="200dp"
/>
</FrameLayout>
<com.example.arantik.test13.MyMediaController
android:id="@+id/myMediaController"
android:layout_width="match_parent"
android:layout_height="108dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="366dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#ff0000"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
更新
如果您想在RelativeLayout中使用此功能,请将android:layout_置于LinearLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<VideoView
android:layout_width="match_parent"
android:layout_height="200dp"
/>
</FrameLayout>
<com.example.arantik.test13.MyMediaController
android:id="@+id/myMediaController"
android:layout_width="match_parent"
android:layout_height="108dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="366dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#ff0000"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
父级布局必须是RelativeLayout。请参阅我的答案@ArantikGood understance of RelativeLayout。谢谢@khemraj父级布局必须是RelativeLayout。请参阅我的答案@ArantikGood understance of RelativeLayout。谢谢@khemraj出于某些原因,我必须使用RelativeLayout。是的!通过在LinearLayout上使用以下android:layout_=“@id/myMediaController”,问题得到了解决。非常感谢@Khemraj。出于某些原因,我不得不使用RelativeLayout。是的,就是这样!通过在LinearLayout上使用以下android:layout_=“@id/myMediaController”,问题得到了解决。非常感谢@Khemraj。