【发布时间】:2011-06-04 03:58:02
【问题描述】:
我正在尝试为一个具有两个并排对齐的 imageViews 的 Android 应用程序创建一个 Activity。我当前的布局配置如下:
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingTop="15dip" android:paddingBottom="15dip"
android:background="@drawable/dark_bg">
<ImageView android:id="@+id/numberDays"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="@drawable/counter_01" />
<ImageView android:src="@drawable/counter_days"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:scaleType="fitStart"
android:id="@+id/daysText"></ImageView>
</LinearLayout>
第一个图像是正方形(比如说 100x100),第二个图像是矩形(300x100) - 我希望它们彼此相邻对齐,但始终缩放以适应设备的宽度 -仅通过布局配置就可以吗?
当前配置仅显示第一张图像的整个屏幕宽度(几乎是高度),而第二张图像根本不显示。我尝试使用 fill_parent 和 hardocding 宽度更改 wrap_content,但这只是导致两个图像都显示,但第一个图像位于第二个图像的顶部(都锚定在左侧)。
谢谢
再次更新:
我已经更新了我的布局,现在看起来像这样,包括推荐的 ScrollView,但没有乐趣:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:gravity="top"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<!-- Header for activity - this has the countdown in it -->
<ScrollView android:id="@+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
android:gravity="right"
android:background="@drawable/dark_bg" android:orientation="horizontal">
<ImageView android:id="@+id/numberDays"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="2"
android:src="@drawable/counter_01" />
<ImageView android:src="@drawable/counter_days"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/daysText"/>
</LinearLayout>
</ScrollView>
<!-- main body for the rest of the info -->
<LinearLayout android:orientation="horizontal" android:gravity="center"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/light_bg">
</LinearLayout>
</LinearLayout>
按照建议使用 layout_weight 为两个图像提供了正确的比例并且看起来完美缩放,但是,我仍然遇到问题,即它们都锚定在屏幕的最左侧,所以第一张图像实际上是叠加在第二张图片上,而不是并排放置。
下面是 Eclipse 显示的截图:
【问题讨论】: