Android 相对布局的麻烦

发布于 2025-01-04 10:38:49 字数 2604 浏览 2 评论 0原文

我对相对布局很陌生,我正在努力解决它们;)

我想做的是: http://pineapple.cc/plan.jpg

但我得到的是: http://pineapple.cc/result.jpg

这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageView 
        android:id="@+id/list_poi_image"
        android:src="@drawable/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/list_poi_ll"
        android:background="#000000" />
    <LinearLayout
        android:id="@+id/list_poi_ll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="vertical">
        <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView android:id="@+id/list_poi_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/list_poi_date_created"
                android:text="Name"/>
             <TextView android:id="@+id/list_poi_date_created"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="Date created"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            <TextView android:id="@+id/list_poi_description"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/list_poi_date_planned"
                android:text="Description"/>
             <TextView android:id="@+id/list_poi_date_planned"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="Date planned"/>
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

我做错了什么? ?

感谢您的帮助 !!

I am quite new to relative layouts and I am struggling with them ;)

What I am trying to do is that:
http://pineapple.cc/plan.jpg

But what I get is that:
http://pineapple.cc/result.jpg

This is my code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageView 
        android:id="@+id/list_poi_image"
        android:src="@drawable/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/list_poi_ll"
        android:background="#000000" />
    <LinearLayout
        android:id="@+id/list_poi_ll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="vertical">
        <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView android:id="@+id/list_poi_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/list_poi_date_created"
                android:text="Name"/>
             <TextView android:id="@+id/list_poi_date_created"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="Date created"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            <TextView android:id="@+id/list_poi_description"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/list_poi_date_planned"
                android:text="Description"/>
             <TextView android:id="@+id/list_poi_date_planned"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="Date planned"/>
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

What am I doing wrong ???

Thanks for your help !!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2025-01-11 10:38:49

如果您想充分利用RelativeLayouts,则无需在其他RelativeLayouts/LinearLayouts 中使用RelativeLayouts/LinearLayouts。

有关如何使用RelativeLayouts的示例,请参见:

http://developer.android .com/resources/tutorials/views/hello-relativelayout.html

http://android-developers.blogspot.com/2009/02 /android-layout-tricks-1.html

总之,您正在寻找以下内容:

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

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/image"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/name"
        android:layout_below="@+id/name"
        android:text="Description"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/date_created"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/name"
        android:layout_alignBottom="@+id/name"
        android:layout_alignParentRight="true"
        android:text="DateCreated"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/date_planned"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"            
        android:layout_alignBaseline="@+id/description"
        android:layout_alignBottom="@+id/description"
        android:layout_alignParentRight="true"
        android:text="DatePlanned"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

请注意,硬编码字符串位于其中,使您能够查看文本。确保删除这些并使用 strings.xml 文件。

If you are wanting to use RelativeLayouts to the best of there abilities, there is no need to have RelativeLayouts/LinearLayouts within other RelativeLayouts/LinearLayouts.

For examples of how to use RelativeLayouts look at:

http://developer.android.com/resources/tutorials/views/hello-relativelayout.html

http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

In terns of what your looking for the following is what you are looking for:

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

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/image"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/name"
        android:layout_below="@+id/name"
        android:text="Description"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/date_created"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/name"
        android:layout_alignBottom="@+id/name"
        android:layout_alignParentRight="true"
        android:text="DateCreated"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/date_planned"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"            
        android:layout_alignBaseline="@+id/description"
        android:layout_alignBottom="@+id/description"
        android:layout_alignParentRight="true"
        android:text="DatePlanned"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

Please note that the hard-coded Strings are in there to enable you to see the text. Ensure you remove these and use a strings.xml file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文