相对布局编码 [英] Relative layout Coding
问题描述
可能重复:结果
OpenGL和Android的相对布局
海兰,我想知道如何code这个XML为code
Hy, I was wondering how to code this xml to code
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@raw/gi"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="64px"
android:layout_height="64px"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/b1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="64px"
android:layout_height="64px"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
android:src="@drawable/b2" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="64px"
android:layout_height="64px"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView2"
android:src="@drawable/b3" />
</RelativeLayout>
因为我需要它放在完全一样的。
所有我走到这一步,是
as I need it to be placed exactly like that. all I got so far is
gi = new RelativeLayout(this);
gi.setBackgroundResource(R.raw.gi);
img1= new ImageView(this);
img1.setImageResource(R.drawable.b1);
img1.setLayoutParams();
img2= new ImageView(this);
img2.setImageResource(R.drawable.b2);
img3= new ImageView(this);
img3.setImageResource(R.drawable.b3);
gi.addView(img1,64,64);
gi.addView(img2,64,64);
gi.addView(img3,64,64);
我显然遇到一些麻烦,我不能在文档中找到alignparents。也是这些像素,DPI的或者在addview东西
I'm obviously having some trouble with alignparents which I can't find in the documentation. Also are these pixels, dpi's or something else in the addview
推荐答案
A RelativeLayout的
可在大多数情况下是有用的,但在这个特殊的一个,你可能会得到更好的服务通过以下内容:
A RelativeLayout
can be useful in most cases, but in this particular one, you may be better served by the following:
<LinearLayout android:orientation="horizontal" android:layout_width="match_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="64px"
android:layout_height="64px"
android:src="@drawable/b1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="64px"
android:layout_height="64px"
android:src="@drawable/b2" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="64px"
android:layout_height="64px"
android:src="@drawable/b3" />
</LinearLayout>
要回答你原来的问题,这些都显示不正常的原因是因为这样:
To answer your original question, the reason these are not displaying properly is because of this:
android:layout_toRightOf="@+id/imageView1"
查看 @ + ID
?这是创建这个观点,这混淆了一个新的XML实例 ID
秒。
See the @+id
? That is creating a new instance of this view, which confuses the XML id
s.
你应该使用是这样的:
android:layout_toRightOf="@id/imageView1"
希望这有助于!
这篇关于相对布局编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!