【发布时间】:2015-01-30 02:54:25
【问题描述】:
我正在学习 Head First Android Development 的教程,但我不明白为什么 LinearLayout 不能正常工作。
这里是xml代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/imageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_image_title"/>
<TextView
android:id="@+id/imageDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_image_date"/>
<ImageView
android:id="@+id/imageDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/test_image"/>
<TextView
android:id="@+id/imageDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_image_description"/>
</LinearLayout>
问题是图像在中间,但图像应该正好在上面显示的两行文本下方,而不是在中间。最后一个 TextView 也根本没有显示。一切都应该按照 xml 中声明的顺序显示。
至少教程是这样显示的。
我尝试将 ImageView 部分放在 TextViews 之上,然后我根本没有得到任何文本,并且图像仍在中间。
自从这本书出版以来,行为发生了变化还是我遗漏了什么?
【问题讨论】:
-
这是您在设计视图或实际应用中看到的内容吗?
-
test_image 的高度是多少?
-
在注释掉 ImageView 后看看你是否得到了正确的行为。如果您看到文本以正确的顺序出现,那么您的 ImageView 有问题。你能发布“@drawable/test_image”的大小和类型吗?
-
尝试将
ImageView的大小设置为56dp*56dp 之类的小值,或者在<LinearLayout>周围放置一个<ScrollView>。有些东西告诉我图片太大了。 -
图片尺寸为1000x773。
标签: android textview imageview android-linearlayout