Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 应用程序小部件布局:图像上方的文本行,在边框内居中_Android_Android Layout_Android Widget - Fatal编程技术网

Android 应用程序小部件布局:图像上方的文本行,在边框内居中

Android 应用程序小部件布局:图像上方的文本行,在边框内居中,android,android-layout,android-widget,Android,Android Layout,Android Widget,我有一个非常简单的应用程序小部件布局:图像上方的一行文本 图像应缩放以适应小部件的边界框(保持纵横比),文本应与其下方的图像左对齐。它们应该一起出现在小部件的包围盒的中间。 我不能让它工作。我所能做到的最好方法是对齐边界框的左上角,如下所示: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

我有一个非常简单的应用程序小部件布局:图像上方的一行文本

图像应缩放以适应小部件的边界框(保持纵横比),文本应与其下方的图像左对齐。它们应该一起出现在小部件的包围盒的中间。

我不能让它工作。我所能做到的最好方法是对齐边界框的左上角,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
    <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
    />
    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_gravity="top"
        android:scaleType="fitStart"
    />
</LinearLayout>

我无法指定将顶部居中对齐的
缩放类型
,也无法使图像视图占用图像所需的空间。

试试看,如果您希望布局在横向模式下显示为所需的样子,则必须为横向模式制作另一个布局或将视图保持在纵向模式

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
    android:id="@+id/txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/img"
    android:text="Text Line"
    android:textColor="@color/black" />

<ImageView
    android:id="@+id/img"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:adjustViewBounds="true"
    android:src="@drawable/signuptop" />

</RelativeLayout>


您应该使用相对布局、框架布局或坐标布局,它们可以更好地调整视图,而线性布局则不行。您能否向图像显示实际需要的内容,但实际拥有的内容?这似乎适用于高大的边界框,但在宽视图中失败,因为图像视图上没有为文本视图留出空间的约束。我想针对每种情况的专门布局可以做到这一点。