开发者

Display two Image views horizontally

I have the following requirements.

  1. I am displaying two blank images(ImageView) in landscape mode.
  2. Based on some logic, I need to put two TextViews on each image. For this reason, I am using a class which extends BaseAdapter.

I ha开发者_运维技巧ve already created the same using Gallery for multiple images (images more than 2), but the requirement is that for two images, it should not be scrollable & also there will not be any centre image, as is the case when I am using Gallery where an Image occupies the centre portion of the screen.

The two images needs to be spaced e.g., Image 1 should have 20dip from left margin whereas Image2 should have 20dip from right margin.

Kindly provide the logic/sample code to implement the same.

The class extending BaseAdapter is working fine. I need only the Layout related details for displaying the two image on a horizontal manner.


What about having two images in a horizontal LinearLayout? Your res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="10dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView android:id="@+id/image_1"
        android:layout_weight="1"
        android:layout_gravity="center_vertical"
        android:padding="10dp"
        android:adjustViewBounds="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <ImageView android:id="@+id/image_2"
        android:layout_weight="1"
        android:layout_gravity="center_vertical"
        android:padding="10dp"
        android:adjustViewBounds="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</Linearlayout>

and then in your java code you can switch out images easily using the ImageView#setImageFoo methods:

ImageView first = (ImageView) findViewById(R.id.image_1);
first.setImageResource(R.drawable.my_picture);

where my_picture.png would be an image in your res/drawables folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜