简体   繁体   English

Android相对布局底部边距无法正常工作

[英]Android relative layout bottom margin not working correctly

I'm creating a dynamic layout application for the first time. 我是第一次创建动态布局应用程序。 I'm fetching the data from an online database and using an XML layout to present it to the user. 我正在从在线数据库中获取数据,并使用XML布局将其呈现给用户。

I'm having an issue with the bottom margin. 我的下边距有问题。 It's being covered up by another layout that it inside the main relative layout and I have tried everything to make it show and got no results. 它被另一个相对布局掩盖了,它位于主要相对布局内,而我已经尽一切努力使它显示并且没有结果。

So after nearly two hours of playing with the setting I have decided to ask you guys, to point me out on what I am doing wrong. 因此,在使用设置近两个小时之后,我决定请大家指出我做错了什么。

This is how it looks on the screen 这是它在屏幕上的外观

Android利润率问题

You can notice the bottom gray border part is missing. 您会注意到底部的灰色边框部分丢失了。 I'm using a relative layout inside of a relative layout. 我在相对布局中使用相对布局。 So the main layout is gray and serves as background for the border, while the second relative layout actually contains all other views. 因此,主布局为灰色并用作边框的背景,而第二个相对布局实际上包含所有其他视图。

This is my XML file 这是我的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="wrap_content"
    android:background="#ffffff"
    android:id="@+id/item_container">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_marginRight="5dp"
            android:background="#e8e8e8"
            android:id="@+id/item_body"
            android:layout_alignParentTop="false"
            android:layout_alignParentLeft="false"
            android:layout_alignParentRight="false"
            android:layout_alignWithParentIfMissing="false"
            android:layout_alignParentBottom="false"
            android:layout_marginBottom="5dp"
            android:layout_margin="5dp">

            <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@color/background"
                android:id="@+id/item_button"
                android:layout_margin="2dp"
                android:clickable="true"
                android:longClickable="true"
                android:focusable="true"
                android:focusableInTouchMode="false"
                android:minHeight="55dp">

                <FrameLayout
                    android:layout_width="3dp"
                    android:layout_height="fill_parent"
                    android:background="@android:color/transparent"
                    android:id="@+id/item_indicator"></FrameLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="141-SAMOBOR-RAKOV POTOK-JAGNJIĆ DOL"
                    android:id="@+id/item_text"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="30dp"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:gravity="fill" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/item_icon"
                    android:layout_gravity="center_vertical|right"
                    android:background="@android:color/transparent"
                    android:src="@drawable/plus_t"
                    android:layout_marginRight="5dp"
                    android:contentDescription="Proširi" />

            </FrameLayout>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/item_image_container"
            android:layout_below="@+id/item_body"
            android:layout_marginTop="5dp"
            android:background="#ffffff">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/item_image"
                android:background="@android:color/transparent"
                android:layout_centerHorizontal="true"
                android:scaleType="fitCenter" />
        </RelativeLayout>

</RelativeLayout>

I have added an image of the structure so it's easier to understand what I am doing here. 我已经添加了该结构的图像,因此更容易理解我在这里所做的事情。

在此处输入图片说明

I apologize of this questions sounds noobish or something, this is my third app for Android and I'm still learning, I'm trying to learn on how to create dynamic views/layouts with this one. 我为这个问题感到抱歉,这是我的第三个Android应用程序,我仍在学习中,我正在尝试学习如何使用此应用程序创建动态视图/布局。 I appreciate the time you guys are taking to read and assist me with this. 我感谢你们花时间阅读和帮助我。

Thanks in advance. 提前致谢。

Here's how your 2nd RelativeLayout and 1st FrameLayout should look. 这是您的2nd RelativeLayout和1st FrameLayout的外观。 You aren't making use of the padding attribute. 您没有使用padding属性。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:padding="2dp"
    android:background="#e8e8e8"
    android:id="@+id/item_body">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white"
        android:id="@+id/item_button"
        android:clickable="true"
        android:longClickable="true"
        android:focusable="true"
        android:focusableInTouchMode="false"
        android:minHeight="55dp">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM