简体   繁体   English

Android 2.1中的XML布局

[英]XML Layout in Android 2.1

I'm trying to do row layout like this: 我试图做这样的行布局:

    Text1  Text3
IMG 
    Text2  Text4

Here is my xml code. 这是我的xml代码。 It displays Text1 Text2 Text3 Text4 correctly, but I don't know how to insert image in the left side. 它正确显示Text1 Text2 Text3 Text4,但是我不知道如何在左侧插入图像。 I am starting to think that using RelativeLayout is bad idea. 我开始认为使用RelativeLayout是个坏主意。 :( :(

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


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@android:id/text1"
            android:src="@drawable/ic_launcher" />

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

        <TextView
              android:id="@android:id/text1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true" 
              android:clickable="false"
              android:paddingBottom="1pt"
              android:paddingLeft="6dip"
              android:paddingTop="5pt"
              android:textStyle="bold"
              android:textSize="9pt"/>

        <TextView
              android:id="@+id/text3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:clickable="false"
              android:paddingBottom="1pt"
              android:paddingRight="11dip"
              android:paddingTop="6pt"
              android:textColor="#a0a0a0"
              android:textSize="7pt" />


    </RelativeLayout>

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

   <TextView
       android:id="@+id/text2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentLeft="true"
       android:clickable="false"
       android:paddingBottom="5pt"
       android:paddingLeft="6dip"
       android:paddingTop="1pt"
       android:textColor="#FFFFFF"
       android:textSize="8pt" />


      <TextView
       android:id="@+id/text4"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:clickable="false"
       android:layout_alignParentRight="true"
       android:paddingBottom="1pt"
       android:paddingRight="11dip"
       android:paddingTop="2pt"
       android:textColor="#a0a0a0"
       android:textSize="7pt" />

   </RelativeLayout>

</LinearLayout> 

since your outermost layout is a LinearLayout, the three child objects (the ImageView and the two RelativeLayouts) will be simply stacked vertically within. 由于您最外面的布局是LinearLayout,所以三个子对象(ImageView和两个RelativeLayouts)将简单地垂直堆叠在其中。 The layout_toRightOf attribute for the ImageView is not valid in the context of the LinearLayout, and will be ignored. ImageView的layout_toRightOf属性在LinearLayout的上下文中无效,将被忽略。

it looks like you're trying to do three columns, essentially? 看起来您基本上想做三栏吗? In that case, make the LinearLayout orientation horizontal, then have three children (the three columns), the first being the image, and the other two can be relative layouts with two children each, those being the texts for the top and bottom of the column. 在这种情况下,将LinearLayout方向设置为水平,然后有三个子级(三列),第一个是图像,另外两个可以是相对布局,每个都有两个子级,它们是文本顶部和底部的文本柱。

However, ultimately, I would suspect that you could be successful with just a RelativeLayout as the outermost, then the ImageView and four TextViews as direct children. 但是,最终,我会怀疑仅靠RelativeLayout作为最外层,然后使用ImageView和四个TextView作为直接子代就可以成功。 These could each be placed relative to the parent (the RelativeLayout) using layout_alignParentLeft, layout_centerVertical, etc etc. For fine tuning, apply padding and margin to the child elements (or even the parent as appropriate). 可以使用layout_alignParentLeft,layout_centerVertical等将它们分别相对于父级(RelativeLayout)放置。要进行微调,请将padding和margin应用于子级元素(或适当时甚至父级)。

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

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