java - 安卓 : Design shown in XML not reflected in the UI

标签 java android xml android-layout

我正在开发一个 Android 应用程序,我在该应用程序中显示注释。之前我在为 noteImage 指定 180X180DP 大小时遇到​​的问题是图像的右侧被切掉了。所以我指定了 match_parent。

当我这样做时,XML 预览会正确显示它,但当我运行该应用程序时,文本会出现在图像下方和图像之外,图像也会向下移动,而标题(主题)会向上移动。检查下面的屏幕截图:

How image is messed up

我想做的是像下面这样的事情,只有 2 列我正在使用 GridView 并指定 columns = 2;但方形图像。我已经在代码中将列表指定为 GridView。 enter image description here

显示布局的 XML 文件。:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="2.5dip" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/noteImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
        <TextView
            android:id="@+id/noteTag"
            android:layout_width="match_parent"
            android:layout_height="26dp"
            android:visibility="visible"
            android:gravity="center"
            android:layout_gravity="center_horizontal|top"
            android:maxLines="1"
            android:ellipsize="end"
            android:scrollHorizontally="true"
            android:layout_marginTop="2dp" />

        <TextView
            android:layout_width="165dp"
            android:layout_height="140dp"
            android:id="@+id/noteText"
            android:layout_gravity="center_horizontal|bottom"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="30dp" />
    </FrameLayout>
</RelativeLayout>

请让我知道我能做什么。非常感谢。 :-)

更新的 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="2.5dip" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
     <!--   <ImageView
            android:id="@+id/noteImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />-->
        <TextView
            android:id="@+id/noteTag"
            android:layout_width="match_parent"
            android:layout_height="37dp"
            />

        <TextView
            android:layout_width="200dp"
            android:layout_height="178dp"
            android:id="@+id/noteText"
            />
    </FrameLayout>
</RelativeLayout>

更新截图:http://postimg.org/image/mgmzca8nx/

最佳答案

在 TextView 上使用 android:background="@drawable/your_drawable"android:background="@color/your_color"

像这样:

<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@color/magenta"
   android:padding="16dp"/>

关于java - 安卓 : Design shown in XML not reflected in the UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33103673/

相关文章:

java - Java 中的排序

java - 根据用户选择将数据从微调器传递到 TextView

android - 如何获取捕获的图像文件路径并保存到数据库?

java - 以编程方式在 fragment 中包含 View 中的布局

java - Runtime.exec() 的行为不符合预期

Java 等待多个线程,这可能会创建新线程

android - 在列表项布局中设置重力

android - 屏幕打开时更新 Android Widget

ruby-on-rails - 如何从 Rails XML 输出中排除特定字段

c# - 如何将文档类型添加到 XDocument?