在Android中创建Bookshelf视图

时间:2013-01-29 22:53:50

标签: android android-layout android-image

我见过很多书架式设计的电子书阅读器,书籍的放置类似于iBooks for Apple或iReader for Android。我正在尝试在Android中构建类似的书架UI。我准备了布局的图形,即shelf_left(34 * 180),shelf_right(34 * 180)和shelf_center(652 * 180)。目前我的目标是720 * 1280像素密度设备,因此我将总宽度保持为720px。我使用dp作为我的长度单位。

我使用RelativeLayout作为我的根布局。当我将所有图像放入布局时,图像无法正确对齐。 shelf_center获得额外的顶部和底部填充,侧面图像看起来太大。

我无法弄清楚如何控制此行为。下面是我的main.xml布局的代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/shelf_left"
        android:layout_width="34dp"
        android:layout_height="180dp"
        android:adjustViewBounds="true"
        android:contentDescription="@string/button"
        android:src="@drawable/shelf_left" />

    <ImageView
        android:id="@+id/shelf_center"
        android:layout_width="652dp"
        android:layout_height="180dp"
        android:layout_toLeftOf="@+id/shelf_right"
        android:layout_toRightOf="@+id/shelf_left"
        android:adjustViewBounds="true"
        android:contentDescription="@string/button"
        android:src="@drawable/shelf_center" />

    <ImageView
        android:id="@+id/shelf_right"
        android:layout_width="34dp"
        android:layout_height="180dp"
        android:layout_alignParentRight="true"
        android:adjustViewBounds="true"
        android:contentDescription="@string/button"
        android:src="@drawable/shelf_right" />

</RelativeLayout>

它的外观如下:

http://img210.imageshack.us/img210/2885/shelf.png

请帮我弄清楚我在这里做错了什么。

1 个答案:

答案 0 :(得分:0)

似乎中心图像太宽而无法适应视图并缩小。请注意,侧视图中的垂直木质侧面与底视图的图像不匹配。您是否尝试使用android:scaleType以便图像不会缩放?

另外,仔细检查以像素为单位的测量值(您提到图像的大小(以像素为单位))与XML中设置的dp中的值匹配。