怎麼樣在一個水平的兩個圖像LinearLayout
?您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>
,然後在Java代碼中,你可以切換出易於使用ImageView#setImageFoo
方法圖像:
ImageView first = (ImageView) findViewById(R.id.image_1);
first.setImageResource(R.drawable.my_picture);
其中my_picture.png
將是您的res/drawables
文件夾中的圖像。
由於以下原因,我正在使用BaseAdapter:1>這兩個圖像具有一些功能,可以將它們刪除並將值存儲在數據庫中。基本上,我在橫向模式下顯示2個項目的列表。在每張圖片上,我都添加了一個textview和一個刪除圖標。由於其中一些功能,我正在通過適配器傳遞文本值,刪除圖標。所以,正常添加2 ImageViews到我的佈局文件不會工作。它應該是通過調用BaseAdapter類將第一個圖像添加到佈局中,然後將下一個圖像同樣添加到現有列表中。 – chiranjib 2011-03-21 21:00:37
我不認爲你必須爲此使用一個列表。您可以使用兩個自定義視圖。但是,如果您需要執行基於水平適配器的視圖,則可以嘗試使用GridView,並確保它可以適合兩行中的項目。 – 2011-03-21 21:02:16
感謝馬修,我正在使用GridView。你可以建議,如何使GridView佈局文件,第一個圖像定位50從左佈局頁邊距和第二個圖像定位50從右佈局頁邊距下降? – chiranjib 2011-03-21 21:20:25