一组不适合横向模式的图像视图
我有一组 10 个图像视图需要设置在屏幕顶部。在人像模式下,完美符合要求。但是,当我将屏幕方向变为横向时,图像数量保持不变,但宽度不适合布局。我的意思是,一组 10 个图像视图仅占屏幕的 50%。
我尝试了很多不同的方式,但仍然无法对横向做到这一点
这是我的 xml 说 main.xml
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_alignParentTop="true"
android:id="@+id/progresslayout"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentLeft="true"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb4"
android:layout_toRightOf="@+id/pb3" android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb5"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb6"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb7"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb8"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb9"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb10"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
</LinearLayout>
</RelativeLayout>
我也尝试给予 android:layout_weight=" " 属性,但仍然没有用。我在这里注意到的有趣的事情是,而不是图像视图,如果我尝试使用某些按钮或编辑文本字段进行相同的操作,它对于纵向和横向都可以很好地工作
I have a set of 10 image views that need to be set on the top of screen. In the portrait mode, it is perfect as per the requirement. But when I turn the screen orientation to landscape, the number of images remains same but width wise not fitting to the layout. I mean set of 10 image views fills only 50% of the screen.
I tried in many different ways, but still I am not able to do it for landscape
Here is my xml say main.xml
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_alignParentTop="true"
android:id="@+id/progresslayout"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentLeft="true"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb4"
android:layout_toRightOf="@+id/pb3" android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb5"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb6"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb7"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb8"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb9"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb10"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
</LinearLayout>
</RelativeLayout>
I tried giving android:layout_weight=" " property also but still no use. And interesting thing I noticed here is instead of image view, if I try the same thing with some button or edit text filed, it works fine for both portrait and landscape
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
就这样,记住
将
android:src="@drawable/ic_launcher"
替换为您的图像资源。这将在屏幕顶部创建十个图像,彼此之间间隔良好。如果您不想在图像之间留有空间,请为每个图像使用
android:scaleType="fitXY"
属性。祝你好运。There you go
Remember to replace
android:src="@drawable/ic_launcher"
with your image resource. This will create ten images on top the screen nicely spacing between each other.If you don't want space between images, use
android:scaleType="fitXY"
property for each images. Good luck.在 Linearlayout 标签中删除
属性并更改
尝试一下
In the Linearlayout tag remove
attribute and change
Try it
尝试使用
android:layout_weight="1"
和android:layout_width="fill_parent"
。这将确保所有对象共享整个布局宽度并且每个对象占用相同的空间。Try to use
android:layout_weight="1"
andandroid:layout_width="fill_parent"
. This will make sure that all objects share the whole layout width and each takes the same space.尝试,
Try,