相对布局 - 杆按钮向下 [英] Relative layout - stick buttons to bottom

查看:220
本文介绍了相对布局 - 杆按钮向下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个子相对布局相对布局:

第一子布局包含两个文本视图,第二子相对布局低于第一子相对布局。然而,当我所有的设计看起来不错。当手机呈现的按钮不对准第二次相对布局底部。这里是我的code:

 < RelativeLayout的
            机器人:ID =@ + ID / relative_txt
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =FILL_PARENT
            机器人:layout_alignBottom =@ + ID / relative_img
            机器人:layout_alignTop =@ + ID / relative_img
            机器人:layout_marginLeft =05dp
            机器人:layout_marginTop =15dp
            机器人:layout_toLeftOf =@ + ID / imageView1
            机器人:layout_toRightOf =@ + ID / relative_img>            < RelativeLayout的
                机器人:ID =@ + ID / relative_txt1
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT>                <的TextView
                    机器人:ID =@ + ID / textView2
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_alignParentLeft =真
                    机器人:layout_alignParentRight =真
                    机器人:文字=迈克·安德森
                    机器人:文字颜色=#ea2634
                    机器人:TEXTSIZE =14sp
                    机器人:文字样式=大胆/>                <的TextView
                    机器人:ID =@ + ID / textView3
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_alignLeft =@ + ID / textView2
                    机器人:layout_alignParentRight =真
                    机器人:layout_below =@ + ID / textView2
                    机器人:layout_marginTop =02dp
                    机器人:文字=我的新家
                    机器人:文字颜色=#000000
                    机器人:TEXTSIZE =12SP
                    机器人:文字样式=大胆/>
            < / RelativeLayout的>            < RelativeLayout的
                机器人:ID =@ + ID / relative_btn
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =FILL_PARENT
                机器人:layout_alignLeft =@ + ID / relative_txt1
                机器人:layout_alignRight =@ + ID / relative_txt1
                机器人:layout_alignParentBottom =真
                机器人:layout_below =@ + ID / relative_txt1>                <按钮
                    机器人:ID =@ + ID /按钮1
                    机器人:layout_width =20dp
                    机器人:layout_height =20dp
                    机器人:layout_alignParentBottom =真
                    机器人:layout_alignParentLeft =真
                    机器人:layout_marginBottom =04dp
                    机器人:背景=@绘制/ icon_share/>                < ImageView的
                    机器人:ID =@ + ID / imageView3
                    机器人:layout_width =20dp
                    机器人:layout_height =20dp
                    机器人:layout_alignParentBottom =真
                    机器人:layout_centerHorizo​​ntal =真
                    机器人:contentDescription =@字符串/ imageviewContactus
                    机器人:SRC =@绘制/ icon_email/>                <按钮
                    机器人:ID =@ + ID /按钮2
                    机器人:layout_width =20dp
                    机器人:layout_height =20dp
                    机器人:layout_alignParentBottom =真
                    机器人:layout_alignParentRight =真
                    机器人:背景=@绘制/ icon_call/>
            < / RelativeLayout的>
        < / RelativeLayout的>

我要坚持到底换挡,而且如果有空间的第二个文本视图下方排列的按钮。
任何暗示什么,我缺少什么?

这是我的完整列表视图行code:

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / relativePrime
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>    < RelativeLayout的
        机器人:ID =@ + ID / relative_left
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_toLeftOf =@ + ID / relative_right>        <查看
            机器人:ID =@ + ID / leftView
            机器人:layout_width =05dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignBottom =@ + ID / relative_img
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentTop =真
            机器人:背景=#560978/>        < RelativeLayout的
            机器人:ID =@ + ID / relative_img
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentTop =真
            机器人:layout_marginLeft =10dp>            < ImageView的
                机器人:ID =@ + ID / imageView2
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_alignParentLeft =真
                机器人:layout_alignParentTop =真
                机器人:背景=@绘制/ icon_default
                机器人:contentDescription =@字符串/ imageviewContactus/>            <的TextView
                机器人:ID =@ + ID / dateText
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_below =@ + ID / imageView2
                机器人:layout_centerHorizo​​ntal =真
                机器人:文字=TextView的/>
        < / RelativeLayout的>        < RelativeLayout的
            机器人:ID =@ + ID / relative_txt
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =FILL_PARENT
            机器人:layout_alignBottom =@ + ID / relative_img
            机器人:layout_alignTop =@ + ID / relative_img
            机器人:layout_marginLeft =05dp
            机器人:layout_marginTop =15dp
            机器人:layout_toLeftOf =@ + ID / imageView1
            机器人:layout_toRightOf =@ + ID / relative_img>            < RelativeLayout的
                机器人:ID =@ + ID / relative_txt1
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT>                <的TextView
                    机器人:ID =@ + ID / textView2
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_alignParentLeft =真
                    机器人:layout_alignParentRight =真
                    机器人:文字=迈克·安德森
                    机器人:文字颜色=#ea2634
                    机器人:TEXTSIZE =14sp
                    机器人:文字样式=大胆/>                <的TextView
                    机器人:ID =@ + ID / textView3
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_alignLeft =@ + ID / textView2
                    机器人:layout_alignParentRight =真
                    机器人:layout_below =@ + ID / textView2
                    机器人:layout_marginTop =02dp
                    机器人:文字=我的新家
                    机器人:文字颜色=#000000
                    机器人:TEXTSIZE =12SP
                    机器人:文字样式=大胆/>
            < / RelativeLayout的>            < RelativeLayout的
                机器人:ID =@ + ID / relative_btn
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =FILL_PARENT
                机器人:layout_alignLeft =@ + ID / relative_txt1
                机器人:layout_alignRight =@ + ID / relative_txt1
                机器人:layout_alignParentBottom =真
                机器人:layout_below =@ + ID / relative_txt1>                <按钮
                    机器人:ID =@ + ID /按钮1
                    机器人:layout_width =20dp
                    机器人:layout_height =20dp
                    机器人:layout_alignParentBottom =真
                    机器人:layout_alignParentLeft =真
                    机器人:layout_marginBottom =04dp
                    机器人:背景=@绘制/ icon_share/>                < ImageView的
                    机器人:ID =@ + ID / imageView3
                    机器人:layout_width =20dp
                    机器人:layout_height =20dp
                    机器人:layout_alignParentBottom =真
                    机器人:layout_centerHorizo​​ntal =真
                    机器人:contentDescription =@字符串/ imageviewContactus
                    机器人:SRC =@绘制/ icon_email/>                <按钮
                    机器人:ID =@ + ID /按钮2
                    机器人:layout_width =20dp
                    机器人:layout_height =20dp
                    机器人:layout_alignParentBottom =真
                    机器人:layout_alignParentRight =真
                    机器人:背景=@绘制/ icon_call/>
            < / RelativeLayout的>
        < / RelativeLayout的>        < ImageView的
            机器人:ID =@ + ID / imageView1
            机器人:layout_width =30dp
            机器人:layout_height =30dp
            机器人:layout_alignParentRight =真
            机器人:layout_centerVertical =真
            机器人:SRC =@绘制/ icon_pet_2x/>
    < / RelativeLayout的>    < RelativeLayout的
        机器人:ID =@ + ID / relative_right
        机器人:layout_width =50dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBottom =@ + ID / relative_left
        机器人:layout_alignParentRight =真
        机器人:layout_alignParentTop =真正的>    < / RelativeLayout的>< / RelativeLayout的>

期望:

目前状态:


解决方案

 < RelativeLayout的
            机器人:ID =@ + ID / relative_txt
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:layout_marginLeft =05dp
            机器人:layout_marginTop =15dp>            <的TextView
                机器人:ID =@ + ID / textView2
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_alignParentLeft =真
                机器人:文字=迈克·安德森
                机器人:文字颜色=#ea2634
                机器人:TEXTSIZE =14sp
                机器人:文字样式=大胆/>            <的TextView
                机器人:ID =@ + ID / textView3
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_alignRight =@ + ID / textView2
                机器人:layout_alignParentRight =真
                机器人:layout_below =@ + ID / textView2
                机器人:layout_marginTop =02dp
                机器人:文字=我的新家
                机器人:文字颜色=#000000
                机器人:TEXTSIZE =12SP
                机器人:文字样式=大胆/>            < ImageView的
                机器人:ID =@ + ID / imageView3
                机器人:layout_width =20dp
                机器人:layout_height =20dp
                机器人:layout_alignParentBottom =真
                机器人:layout_centerHorizo​​ntal =真
                机器人:contentDescription =@字符串/ imageviewContactus
                机器人:SRC =@绘制/ icon_email/>            <按钮
                机器人:ID =@ + ID /按钮2
                机器人:layout_width =20dp
                机器人:layout_height =20dp
                机器人:layout_alignParentBottom =真
                机器人:layout_alignParentRight =真
                机器人:背景=@绘制/ icon_call/>            <按钮
                机器人:ID =@ + ID /按钮1
                机器人:layout_width =20dp
                机器人:layout_height =20dp
                机器人:layout_alignParentBottom =真
                机器人:layout_alignParentLeft =真
                机器人:背景=@绘制/ icon_share/>        < / RelativeLayout的>

我已经做了一些改变:

1-在我已删除了相对布局的父标签的android:layout_alignBottom 的android:layout_alignTop 的android:layout_toLeftOf 的android:layout_toRightOf 不需要它们,因为你已经设置的宽度和高度 match_parent

2-在textView2标记删除的android:layout_alignParentRight ,因为使用它与的android:layout_alignParentLeft 可通过设置更换与 match_parent

宽度

3- textView3改为的android:layout_alignLeft 一起textView2 的android:layout_alignRight ,因为没有任何意义左对齐的视图,右对齐父!

4- button1的标签去掉机器人:layout_alignTop标签,因为它引用视图这是不是在同一范围内的父相对布局,所以这条线将无法正常工作

请让这些变化,使屏幕截图的结果。

I have a relative layout with two sub relative layouts:

The first sub layout contains two text views, the second sub relative layout is below the first sub relative layout. However when I design all looks fine. When rendered on phone the buttons don't align to the second sub relative layouts bottom. Here is my code:

 <RelativeLayout
            android:id="@+id/relative_txt"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignBottom="@+id/relative_img"
            android:layout_alignTop="@+id/relative_img"
            android:layout_marginLeft="05dp"
            android:layout_marginTop="15dp"
            android:layout_toLeftOf="@+id/imageView1"
            android:layout_toRightOf="@+id/relative_img" >

            <RelativeLayout
                android:id="@+id/relative_txt1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentRight="true"
                    android:text="Mike Anderson"
                    android:textColor="#ea2634"
                    android:textSize="14sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView2"
                    android:layout_alignParentRight="true"
                    android:layout_below="@+id/textView2"
                    android:layout_marginTop="02dp"
                    android:text="My New Home"
                    android:textColor="#000000"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/relative_btn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_alignLeft="@+id/relative_txt1"
                android:layout_alignRight="@+id/relative_txt1"
                android:layout_alignParentBottom="true"
                android:layout_below="@+id/relative_txt1" >

                <Button
                    android:id="@+id/button1"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginBottom="04dp"
                    android:background="@drawable/icon_share" />

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:contentDescription="@string/imageviewContactus"
                    android:src="@drawable/icon_email" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:background="@drawable/icon_call" />
            </RelativeLayout>
        </RelativeLayout>

The buttons I want to stick to the bottom shift up and are aligned below the second text view if there is space. Any hints what I am missing?

This is my complete list view row code:

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativePrime"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/relative_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/relative_right" >

        <View
            android:id="@+id/leftView"
            android:layout_width="05dp"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/relative_img"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:background="#560978" />

        <RelativeLayout
            android:id="@+id/relative_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="10dp" >

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:background="@drawable/icon_default"
                android:contentDescription="@string/imageviewContactus" />

            <TextView
                android:id="@+id/dateText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imageView2"
                android:layout_centerHorizontal="true"
                android:text="TextView" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/relative_txt"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignBottom="@+id/relative_img"
            android:layout_alignTop="@+id/relative_img"
            android:layout_marginLeft="05dp"
            android:layout_marginTop="15dp"
            android:layout_toLeftOf="@+id/imageView1"
            android:layout_toRightOf="@+id/relative_img" >

            <RelativeLayout
                android:id="@+id/relative_txt1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentRight="true"
                    android:text="Mike Anderson"
                    android:textColor="#ea2634"
                    android:textSize="14sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView2"
                    android:layout_alignParentRight="true"
                    android:layout_below="@+id/textView2"
                    android:layout_marginTop="02dp"
                    android:text="My New Home"
                    android:textColor="#000000"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/relative_btn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_alignLeft="@+id/relative_txt1"
                android:layout_alignRight="@+id/relative_txt1"
                android:layout_alignParentBottom="true"
                android:layout_below="@+id/relative_txt1" >

                <Button
                    android:id="@+id/button1"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginBottom="04dp"
                    android:background="@drawable/icon_share" />

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:contentDescription="@string/imageviewContactus"
                    android:src="@drawable/icon_email" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:background="@drawable/icon_call" />
            </RelativeLayout>
        </RelativeLayout>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/icon_pet_2x" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relative_right"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/relative_left"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

    </RelativeLayout>

</RelativeLayout>

Desired:

Current status:

解决方案

<RelativeLayout
            android:id="@+id/relative_txt"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="05dp"
            android:layout_marginTop="15dp" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:text="Mike Anderson"
                android:textColor="#ea2634"
                android:textSize="14sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignRight="@+id/textView2"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/textView2"
                android:layout_marginTop="02dp"
                android:text="My New Home"
                android:textColor="#000000"
                android:textSize="12sp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:contentDescription="@string/imageviewContactus"
                android:src="@drawable/icon_email" />

            <Button
                android:id="@+id/button2"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:background="@drawable/icon_call" />

            <Button
                android:id="@+id/button1"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:background="@drawable/icon_share" />

        </RelativeLayout>

I have made some changes:

1- In the parent tag of relative layout i have removed android:layout_alignBottom, android:layout_alignTop, android:layout_toLeftOf, and android:layout_toRightOf no need for them because you already set width and height match_parent.

2- In textView2 tag removed android:layout_alignParentRight because using it with android:layout_alignParentLeft can be replaced by setting width with match_parent

3- In textView3 changed android:layout_alignLeft to textView2 with android:layout_alignRight because doesn't make sense to align left for a view and align right to parent !!.

4- In button1 tag removed android:layout_alignTop tag because it refer to a view which is not in the same scope "the parent relative layout" so this line will not work.

Please make those changes and make screen shot for the result.

这篇关于相对布局 - 杆按钮向下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆