Android 不适合横向模式的图像视图集
我有一套10个图像视图,需要设置在屏幕顶部。在纵向模式下,根据要求,它是完美的。但当我将屏幕方向改为横向时,图像数量保持不变,但宽度不适合布局。我的意思是一组10个图像视图只占屏幕的50% 我尝试了许多不同的方法,但我仍然无法做到这一点的景观 这是我的xml say main.xmlAndroid 不适合横向模式的图像视图集,android,imageview,orientation,landscape,Android,Imageview,Orientation,Landscape,我有一套10个图像视图,需要设置在屏幕顶部。在纵向模式下,根据要求,它是完美的。但当我将屏幕方向改为横向时,图像数量保持不变,但宽度不适合布局。我的意思是一组10个图像视图只占屏幕的50% 我尝试了许多不同的方法,但我仍然无法做到这一点的景观 这是我的xml say main.xml <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_he
<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=“”属性,但还是没有用。有趣的是,我注意到这里没有图像视图,如果我用一些按钮或编辑文本字段尝试同样的方法,它对Linearlayout标记中的纵向和横向都很好 android:orientation=“水平” 属性与变化 android:layout\u width=“包装内容” 试试看好了
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/progresslayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/pb1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
<ImageView
android:id="@+id/pb10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" >
</ImageView>
</LinearLayout>
记住用您的图像资源替换android:src=“@drawable/ic_launcher”。这将在屏幕顶部创建十个图像,它们之间的间距很好
如果不希望图像之间留有空格,请为每个图像使用
android:scaleType=“fitXY”
属性。祝你好运。尝试使用android:layout\u weight=“1”
和android:layout\u width=“fill\u parent”
。这将确保所有对象共享整个布局宽度,并且每个对象占用相同的空间。请尝试
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:weightSum="2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/progresslayout"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:weightSum="10"
android:orientation="horizontal" >
// Your ImageViews Here
<ImageView
android:id="@+id/pb10"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:src="@drawable/image1" >
</ImageView>
</LinearLayout>
</LinearLayout>
//您的图像视图在此显示
您的线性布局宽度和高度也应该像android:layout\u width=“fill\u parent”android:layout\u height=“fill\u parent”@Padma Kumar,我已经试过了。在这种情况下,图像合适,但图像不可见。如果我将权重设为0或0.2,而不是1,则图像会出现,但不符合布局您是否尝试过其他图像?我在这里发布之前已经测试过了。是的,我尝试过其他图片。这种情况只发生在图像视图中,对于编辑文本或按钮等字段,这项工作我指的是这个资源@drawable/progressgreen
。在我的代码中,我使用@drawable/ic\u launcher
。它很好用。是的,我明白了,但对我来说这和以前一样。如果我将权重设为1,则图像不会显示,但我可以看到图像的存在。你试过10组图片吗。因为我希望相同数量的图像适合纵向和景观的布局内部线性布局的父级应该是相对布局我知道为什么它是必要的吗?你说的是包含10幅图像的布局吗?不,我说的是包含内部布局的最外层线性布局。这只是整个布局的一部分。许多其他内容与外部相对布局相关,因此有必要将相对布局置于外部线性布局之上,这意味着将相同的代码写入相对布局保持在顶部,并给出高度宽度填充