我正在开发一个 Android 应用程序,我在该应用程序中显示注释。之前我在为 noteImage 指定 180X180DP 大小时遇到的问题是图像的右侧被切掉了。所以我指定了 match_parent。
当我这样做时,XML 预览会正确显示它,但当我运行该应用程序时,文本会出现在图像下方和图像之外,图像也会向下移动,而标题(主题)会向上移动。检查下面的屏幕截图:
我想做的是像下面这样的事情,只有 2 列我正在使用 GridView 并指定 columns = 2;但方形图像。我已经在代码中将列表指定为 GridView。
显示布局的 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>
最佳答案
在 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/