Android 布局无法正常工作

标签 android android-layout ui-design

我正在使用文件 main.xml 来设计 Android 中的 UI。不知道为什么最后的TextView (id: ImageDescription) 不起作用。如果我删除 ImageView 标签,最后一个 TextView 将再次工作。 这是我的截图。第一个在没有 ImageView 标签的时候,第二个在有 ImageView

的时候

not <code>ImageView</code> tag with <code>ImageView</code> tag

如您所见,当有图像时,我看不到 Image descriptor: a cartoon tiger 行。 这是我的 main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/imageTitle"
        android:layout_width="fill_parent"
        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:contentDescription="@string/test_contentDescription"
         android:src="@drawable/test_image"/>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView 
            android:id="@+id/imageDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/test_image_description"/>
    </ScrollView>         

</LinearLayout>

谢谢你的帮助:)

最佳答案

您正在将 imageDescription textview 添加到 imageview 下方,并且您的 scrollview 也同时具有和高度作为 fill_parent,一旦尝试此操作

 <TextView 
        android:id="@+id/imageDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/test_image_date"/>


    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView 
            android:id="@+id/imageDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/test_image_description"/>
    </ScrollView> 

     <ImageView
         android:id="@+id/imageDisplay"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:contentDescription="@string/test_contentDescription"
         android:src="@drawable/test_image"/>

我认为图像太大,如果是这种情况,请尝试以适当的百分比为图像和 TextView 指定 layout:weight 参数。

关于Android 布局无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397499/

相关文章:

android - 如何在 Android 中维护多个页脚 View ?

android - 如何摆脱 ViewPager 示例中的白框

c# - 如何将一堆标签添加到 C# 窗体,然后垂直滚动窗体?

Java CLI UI 设计 : frameworks or libraries?

ios - 如何在 ios 中适应不同的屏幕尺寸

android - 将垂直 Recyclerview 项目 View 设置为 height= match_parent 与设备的高度不匹配

java - 缺少类日期选择器

android - 如何在Android上实现照片拼贴

android - 移动应用程序中的 Uber OAuth 最佳实践

android - 如何在android中使用自定义键盘应用程序编写编辑文本