[英]Align different elements to the center - Android
I have 5 images side by side in the center, what i'm looking for is a way to set some of them to visibility="gone"
and the others to realign to the center. 我在中心并排放置了5张图像,我正在寻找的是一种将其中一些设置为
visibility="gone"
而将其他图像重新设置为中心的方法。 Something like this: 像这样:
And here is my layout: 这是我的布局:
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/gameEndFirstPlayerName"
android:layout_centerHorizontal="true" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="25dp"
android:layout_height="20dp"
android:layout_toRightOf="@+id/imageView2"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="25dp"
android:layout_height="20dp"
android:layout_toRightOf="@+id/imageView3"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="25dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="25dp"
android:layout_height="20dp"
android:layout_toLeftOf="@+id/imageView3"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="25dp"
android:layout_height="20dp"
android:layout_toLeftOf="@+id/imageView4"
android:src="@drawable/star" />
</RelativeLayout>
</RelativeLayout>
Thanks for your help! 谢谢你的帮助! Regards Jose
问候何塞
As mentioned in the comments, you can try a LinearLayout with its orientation set to "horizontal". 如评论中所述,您可以尝试将LinearLayout的方向设置为“水平”。 This should allow the ImageViews to line up side by side.
这应该允许ImageViews并排排列。
You can than target each ImageView by their ID findViewById(R.id.imageView1);
然后,可以通过每个ID的ID为目标来定位它们
findViewById(R.id.imageView1);
and do something such as .setVisibility(View.GONE);
并执行诸如
.setVisibility(View.GONE);
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="25dp"
android:layout_height="20dp"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="25dp"
android:layout_height="20dp"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="25dp"
android:layout_height="20dp"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="25dp"
android:layout_height="20dp"
android:src="@drawable/star" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="25dp"
android:layout_height="20dp"
android:src="@drawable/star" />
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.