Android版的LinearLayout和图像 [英] Android LinearLayout and Images

查看:115
本文介绍了Android版的LinearLayout和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我知道这不可能是困难的,但我有与它一时间赫克..我是一个经验丰富的Java程序员,但很新到Android(OK,所以我的工作我的第一个测试程序仍然...)

Ok, I know this can't be hard, but I'm having a heck of a time with it.. I'm a seasoned Java programmer, but very new to Android (ok, so I'm working on my first test app still...)

我想在屏幕上3张图片,一主的形象,占用,也就是说,在屏幕上方的75%,那么两个较小的图像布局水平在它之下。 (想想一个画廊,显示主(当前)的图像,下面有个previous图像图标的左侧,下方的主要下一个图像图标右侧)。

I'd like to have 3 images on the screen, one "main" image that takes up, say, the top 75% of the screen, then two smaller images laid out horizontally underneath it. (Think of a gallery, with the main (current) image displayed, a "previous" image icon below it on the left, and a "next" image icon below the main on the right).

我没有大,小图像,他们只是都大了,我希望他们在缩放的方式显示。现在的问题是,无论我做什么,主的形象占用太多的空间,这样,大多数情况下,底部的图像是不可见的。

I don't have big and small images, they're just all big and I want them to be displayed in a scaled fashion. The problem is no matter what I do, the "main" image takes up way too much space, such that most often, the images on the bottom aren't visible at all.

我知道我可以在主图像高度设置为浸指定数量的已工作,但这时如果我的应用程序去的设备具有不同的密度,它看起来愚蠢的。我尝试过与Android打:layout_weight,但没有运气。我想如果我设置layout_weights平等的,它将使意见占相同的比例,但主的形象只是一直占主导地位,并导致小图像底部被修剪或完全被推关闭屏幕。

I realize that I can set the main image's height to a specified number of dip and that has worked, but then if my app goes to a device with a different density, it will look goofy. I've tried playing with android:layout_weight, but with no luck. I thought if I set the layout_weights equal, it would make the views take up the same proportion, but the "main" image just always dominates and results in the small images being clipped at the bottom or pushed fully off screen.

我也意识到我可能可以使用其他布局,但它似乎很简单,只是有根布局是垂直的LinearLayout,它由一个图像和由2图像的水平的LinearLayout的。事情是这样的:

I also realize I could probably use other layouts, but it seems so simple to just have the root layout be a vertical LinearLayout that consists of an image and a horizontal LinearLayout that consists of 2 images. Something like this:

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

  <ImageView
    android:id="@+id/cbPicView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/cb1"
    android:layout_weight="1"
  />

  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    >

    <ImageView
      android:id="@+id/cbPrevPicView"
      android:layout_width="50dip"
      android:layout_height="50dip"
      android:src="@drawable/cb4"
      android:layout_weight="1"
    />

    <ImageView
      android:id="@+id/cbNextPicView"
      android:layout_width="50dip"
      android:layout_height="50dip"
      android:src="@drawable/cb2"
      android:layout_weight="1"
    />
  </LinearLayout>
</LinearLayout>

很抱歉的长度 - 试图提供尽可能多的细节,我可以。谢谢!

Sorry for the length - trying to provide as much detail as I can. Thanks!

推荐答案

这将使类似:

-------

   1

-------
 2 | 3
-------

布局:

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

  <ImageView
    android:id="@+id/cbPicView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/cb1"
    android:layout_weight="3"
  />

  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    >

    <ImageView
      android:id="@+id/cbPrevPicView"
      android:layout_width="0dp"
      android:layout_height="fill_parent"
      android:src="@drawable/cb4"
      android:layout_weight="1"
    />

    <ImageView
      android:id="@+id/cbNextPicView"
      android:layout_width="0dp"
      android:layout_height="fill_parent"
      android:src="@drawable/cb2"
      android:layout_weight="1"
    />
  </LinearLayout>
</LinearLayout>

这篇关于Android版的LinearLayout和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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