【问题标题】:Layout - Images are not at the bottom and overlap布局 - 图像不在底部并重叠
【发布时间】:2014-12-04 05:33:16
【问题描述】:

正如线程名称所说,我遇到了重叠元素的问题。我需要制作像页脚这样的东西,它总是位于布局的底部并且不会与元素重叠。我在下面发布我的布局。我认为问题在于我如何定位评级栏和线性布局,它应该位于底部。

P.S 不要怪我使用相对布局的方式,slider应该有一个父Relative布局,而ScrollView只能用于一个通用布局...

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="@drawable/background">

<!--android:margin="5dp"-->

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:id="@+id/relative_layout"
    android:background="#4D000000"
    tools:context="com.daimajia.slider.demo.MainActivity">

    <com.daimajia.slider.library.SliderLayout
        android:id="@+id/slider"
        android:layout_width="match_parent"
        custom:pager_animation="Default"
        custom:indicator_visibility="visible"
        custom:pager_animation_span="1100"
        android:layout_height="200dp" />

    <com.daimajia.slider.library.Indicators.PagerIndicator
        android:id="@+id/custom_indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        custom:selected_color="#0095BF"
        custom:unselected_color="#55333333"
        custom:shape="oval"
        custom:selected_padding_left="5dp"
        custom:selected_padding_right="5dp"
        custom:unselected_padding_left="5dp"
        custom:unselected_padding_right="5dp"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        custom:selected_width="6dp"
        custom:selected_height="6dp"
        custom:unselected_width="6dp"
        custom:unselected_height="6dp"
        android:layout_marginBottom="20dp" />

    <com.daimajia.slider.library.Indicators.PagerIndicator
        android:id="@+id/custom_indicator2"
        style="@style/AndroidImageSlider_Corner_Oval_Orange"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Konstitucijos pr. 7A, Vilnius"
        android:textColor="#FFFFFF"
        android:layout_below="@+id/slider"
        android:layout_marginTop="15dp" />

    <ImageButton
        android:id="@+id/pin"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_below="@+id/slider"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dp"
        android:background="@drawable/pin"
        android:layout_marginTop="5dp" />

    <View
        android:id="@+id/divider1"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#433b39"
        android:layout_below="@id/address"
        android:layout_marginTop="10dp" />

    <TextView
        android:id="@+id/work_hours"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/divider1"
        android:text="I - VI 10:00 - 21:00, VII 10:00 - 20:00"
        android:textColor="#FFFFFF"
        android:layout_marginTop="10dp" />

    <View
        android:id="@+id/divider2"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#433b39"
        android:layout_below="@id/work_hours"
        android:layout_marginTop="10dp" />

    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/divider2"
        android:layout_marginTop="10dp"
        android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        android:textColor="#FFFFFF" />

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_below="@+id/description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <fragment
            android:name="com.google.android.youtube.player.YouTubePlayerFragment"
            android:id="@+id/youtube_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </FrameLayout>

    <View
        android:id="@+id/divider3"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#575350"
        android:layout_below="@id/frame_layout"
        android:layout_marginTop="10dp" />

    <RelativeLayout
        android:layout_below="@+id/divider3"
        android:layout_width="fill_parent"
        android:id="@+id/rl"
        android:layout_height="wrap_content">

        <RatingBar
            android:id="@+id/ratingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:numStars="5"
            android:stepSize="1.0"
            android:rating="0" />

        <TextView
            android:layout_width="fill_parent"
            android:id="@+id/rating_text"
            android:layout_below="@+id/ratingBar"
            android:layout_height="wrap_content"
            android:gravity="center"/>

    </RelativeLayout>

    <View
        android:id="@+id/divider4"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#575350"
        android:layout_below="@id/rl" />

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:layout_margin="5dp"
        android:clickable="true">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="" />

        <ImageButton
            android:id="@+id/number"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:background="@drawable/phone" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="" />

        <ImageButton
            android:id="@+id/email"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:background="@drawable/mail" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="" />
    </LinearLayout>

</RelativeLayout>

</ScrollView>

想要的结果: 它实际上是什么样子的:

【问题讨论】:

  • 使用 android:layout_below="id" 作为最后一个 LinearLayout
  • 您必须在两个RelativeLayout内创建RelativeLayout的简单方法。第二个布局适用于第一个布局。在FirstLayout中添加滑块和textview,第二个布局添加两个图像按钮..如果需要两个布局之间的分隔符然后添加Seprator-firstrelativelayout-seprator-secondrelativelayout 。我认为这样可以帮助

标签: java android android-layout


【解决方案1】:

将以下属性添加到底部 LinearLayout ;

android:layout_below="@id/divider4"

更新了您的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context="com.daimajia.slider.demo.MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true"
        android:background="@drawable/background">

        <!--android:margin="5dp"-->

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:id="@+id/relative_layout"
            android:background="#4D000000">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/slider"
                android:layout_width="match_parent"
                custom:pager_animation="Default"
                custom:indicator_visibility="visible"
                custom:pager_animation_span="1100"
                android:layout_height="200dp" />

            <TextView
                android:id="@+id/address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Konstitucijos pr. 7A, Vilnius"
                android:textColor="#FFFFFF"
                android:layout_below="@+id/slider"
                android:layout_marginTop="15dp" />

            <ImageButton
                android:id="@+id/pin"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_below="@+id/slider"
                android:layout_alignParentRight="true"
                android:layout_marginRight="5dp"
                android:background="@drawable/pin"
                android:layout_marginTop="5dp" />

            <View
                android:id="@+id/divider1"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#433b39"
                android:layout_below="@id/address"
                android:layout_marginTop="10dp" />

            <TextView
                android:id="@+id/work_hours"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/divider1"
                android:text="I - VI 10:00 - 21:00, VII 10:00 - 20:00"
                android:textColor="#FFFFFF"
                android:layout_marginTop="10dp" />

            <View
                android:id="@+id/divider2"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#433b39"
                android:layout_below="@id/work_hours"
                android:layout_marginTop="10dp" />

            <TextView
                android:id="@+id/description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/divider2"
                android:layout_marginTop="10dp"
                android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                android:textColor="#FFFFFF" />

            <FrameLayout
                android:id="@+id/frame_layout"
                android:layout_below="@+id/description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <fragment
                    android:name="com.google.android.youtube.player.YouTubePlayerFragment"
                    android:id="@+id/youtube_fragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </FrameLayout>

            <View
                android:id="@+id/divider3"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#575350"
                android:layout_below="@id/frame_layout"
                android:layout_marginTop="10dp" />

            <RelativeLayout
                android:layout_below="@+id/divider3"
                android:layout_width="match_parent"
                android:id="@+id/rl"
                android:layout_height="wrap_content">

                <RatingBar
                    android:id="@+id/ratingBar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:numStars="5"
                    android:stepSize="1.0"
                    android:rating="0" />

                <TextView
                    android:layout_width="match_parent"
                    android:id="@+id/rating_text"
                    android:layout_below="@+id/ratingBar"
                    android:layout_height="wrap_content"
                    android:gravity="center"/>

            </RelativeLayout>

            <View
                android:id="@+id/divider4"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#575350"
                android:layout_below="@id/rl" />

            <LinearLayout
                android:layout_below="@id/divider4"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:orientation="horizontal"
                android:layout_margin="5dp"
                android:clickable="true">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.0"
                    android:text="" />

                <ImageButton
                    android:id="@+id/number"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:background="@drawable/phone" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.0"
                    android:text="" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.0"
                    android:text="" />

                <ImageButton
                    android:id="@+id/email"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:background="@drawable/mail" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.0"
                    android:text="" />
            </LinearLayout>

        </RelativeLayout>

    </ScrollView>

    <com.daimajia.slider.library.Indicators.PagerIndicator
        android:id="@+id/custom_indicator2"
        style="@style/AndroidImageSlider_Corner_Oval_Orange"
        android:layout_marginBottom="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <com.daimajia.slider.library.Indicators.PagerIndicator
        android:id="@+id/custom_indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        custom:selected_color="#0095BF"
        custom:unselected_color="#55333333"
        custom:shape="oval"
        custom:selected_padding_left="5dp"
        custom:selected_padding_right="5dp"
        custom:unselected_padding_left="5dp"
        custom:unselected_padding_right="5dp"
        custom:selected_width="6dp"
        custom:selected_height="6dp"
        custom:unselected_width="6dp"
        custom:unselected_height="6dp"/>
</LinearLayout>

【讨论】:

  • 好吧,我很高兴你试图帮助我,但是,它仍然不起作用。我的完整布局代码只是为了澄清,如果我的想法正确的话:pastebin.com/iqvCAyNy
【解决方案2】:

使用android:layout_below="id of the devider " 因为我不知道它是哪个分隔符

【讨论】:

    【解决方案3】:

    添加:

    android:layout_below="@id/divider4"
    

    最后LinearLayout

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      相关资源
      最近更新 更多