【问题标题】:there is a gap between two relative layouts两个相对布局之间存在间隙
【发布时间】:2016-05-26 13:11:27
【问题描述】:

两个相对布局之间存在间隙。我想消除这个差距。

我的图片的xml如下

<RelativeLayout
    android:id="@+id/live_view_surface_view_rl"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/video_height">

    <RelativeLayout
        android:id="@+id/surfaceview_rl"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/palette_rl">

        <SurfaceView
            android:id="@+id/surfaceview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true">
        </SurfaceView>        
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/palette_rl"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:background="@color/transperent_black_color">

        <RelativeLayout
            android:id="@+id/snapshot_button_rl"
            android:layout_width="50dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="@dimen/margin_left_right">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/snapshotselection" />
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/mic_btn_rl_parent"
            android:layout_width="100dp"
            android:layout_height="fill_parent"
            android:layout_toRightOf="@+id/snapshot_button_rl"
            android:orientation="horizontal">

            <RelativeLayout
                android:id="@+id/mic_button_rl"
                android:layout_width="50dp"
                android:layout_height="fill_parent">

                <ImageView
                    android:id="@+id/mic_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:src="@drawable/talkbackbtn_selector" />

                <ProgressBar
                    android:id="@+id/start_talkback_progress"
                    android:layout_width="@dimen/field_width_small"
                    android:layout_height="@dimen/field_width_small"
                    android:layout_centerInParent="true"
                    android:visibility="gone" />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/live_view_audio_icon_rl"
                android:layout_width="@dimen/field_width_medium"
                android:layout_height="fill_parent">

                <ImageView
                    android:id="@+id/live_view_audio_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:src="@drawable/icon_volume" />
            </RelativeLayout>
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

即使我增加了下面相对布局的高度,这个间隙也保持不变。 两种布局都有相同的父级,但它们仍然没有调整到相同的位置。

【问题讨论】:

  • 请发布您的 xml
  • @Nisarg 这是我的 xml
  • 现在让我检查一下
  • 这是给定身高的空间 android:layout_height="60dp" 请避免硬编码
  • @AditayKaushal 你能建议我改用什么吗?

标签: android xml android-relativelayout


【解决方案1】:

您好,只需复制粘贴并在相对布局中写入您的 xml

<LinearLayout      xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="8">

</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2">

</RelativeLayout>

【讨论】:

  • 用match_parent和palette_rl布局替换你的视频高度也是一个match_parent
【解决方案2】:

将 weightsum=1 设置为父布局(palette_rl)。将 weight=0.25 设置为所有子相对布局并保持其 layout_width=0dip。它工作正常。以相同的顺序调整所有空间。

请使用下面的 xml。我更改了高度和尺寸以及可绘制。所以,请调整它。它工作正常。黑线删除。

<?xml version="1.0" encoding="utf-8"?>
  <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" >
 <RelativeLayout
android:id="@+id/live_view_surface_view_rl"
android:layout_width="fill_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:id="@+id/surfaceview_rl"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
   >

    <SurfaceView
        android:id="@+id/surfaceview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true">
    </SurfaceView>        
</RelativeLayout>

<RelativeLayout
    android:id="@+id/palette_rl"
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:background="#ab00aa">

    <RelativeLayout
        android:id="@+id/snapshot_button_rl"
        android:layout_width="50dp"
        android:layout_height="fill_parent"
        android:layout_marginLeft="10dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/ic_launcher" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/mic_btn_rl_parent"
        android:layout_width="100dp"
        android:layout_height="fill_parent"
        android:layout_toRightOf="@+id/snapshot_button_rl"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/mic_button_rl"
            android:layout_width="50dp"
            android:layout_height="fill_parent">

            <ImageView
                android:id="@+id/mic_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/ic_launcher" />

            <ProgressBar
                android:id="@+id/start_talkback_progress"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerInParent="true"
                android:visibility="gone" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/live_view_audio_icon_rl"
            android:layout_width="50dp"
            android:layout_height="fill_parent">

            <ImageView
                android:id="@+id/live_view_audio_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/ic_launcher" />
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

【讨论】:

  • 我的布局高度有问题,两个布局之间的黑色条在它们的高度
  • 我在答案中添加了 xml 文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多