几个图像的线性布局,不能得到FILL_PARENT / WRAP_CONTENT权 [英] Linear layout of several images, can't get fill_parent/wrap_content right

查看:101
本文介绍了几个图像的线性布局,不能得到FILL_PARENT / WRAP_CONTENT权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有9x2 PNG的一格,我想在我的窗口小部件散发

I have a grid of 9x2 PNG's that I would like to distribute in my widget

在一些提示,我决定去(清理code位)

After some tips I decided to go for (cleaned up the code a bit)

<linearLayout
  android:orientation="vertical">
  <linearLayout
    android:orientation="horizontal">
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
  </linearLayout>
  <linearLayout
    android:orientation="horizontal">
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
      <ImageView />
  </linearLayout>
</linearLayout>

百万美元的问题是如何把元素的宽度/高度。我想对象以填充小部件的整个宽度,因此,宽度=FILL_PARENT上的顶层。但,除了我只想图像很好地扩展。我似乎无法得到的工作和不知道如果我错过了FILL_PARENT / WRAP_CONTENT的概念。

The million dollar question is how to put the width/height of the elements. I'd like the object to fill the whole width of the widget, hence width="fill_parent" on the top level. But apart from that I would just like the images to scale nicely. I can't seem to get that working and wonder if I missed the concept of fill_parent/wrap_content.

我试着用权重参数exeperimenting但由于图像具有不同的尺寸这恰恰没有发挥出来。

I tried exeperimenting with the weight parameter but since the images have different sizes this just didn't work out.

如何界定上述元素的宽度/高度,使这个9x2网格填充的宽度,并采取了尽可能多的空间上高度neccessary将大大AP preciated任何帮助!

Any help on how to define the width/height of the above elements to make this 9x2 grid fill the width and take up as much space as neccessary on the height would be greatly appreciated!

谢谢
约翰·

推荐答案

您必须使用布局参数的android:layout_weight。如果所有imageviews已经layout_weight = 1的空间将同样其中可分为:

You have to use the layout parameter android:layout_weight. If all imageviews have layout_weight=1 the space will be divided equally among them:

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

  <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"  android:background="#0000aa">
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent"  android:background="#ff0000"/>
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent" />
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent"  android:background="#ff0000"/>
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent" />
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent"  android:background="#ff0000"/>
  </LinearLayout>
  <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"  android:background="#00aaaa">
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent"  android:background="#ff0000"/>
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent" />
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent"  android:background="#ff0000"/>
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent" />
      <ImageView android:layout_weight="1" android:src="@drawable/icon" android:scaleType="fitXY" android:layout_width="wrap_content" android:layout_height="fill_parent"  android:background="#ff0000"/>
  </LinearLayout>
</LinearLayout>

这篇关于几个图像的线性布局,不能得到FILL_PARENT / WRAP_CONTENT权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆