我有一个非常简单的应用程序小部件布局:图像上方的一行文本。
图像应缩放以适合小部件的边界框(保持纵横比(,并且文本应与其下方的图像左对齐。它们应该一起出现在小部件边界框的中间。
我无法让它工作。我管理的最好的方法是对齐边界框的左上角,如下所示:
<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>
我无法指定一个将顶部居中对齐的scaleType
,我也无法使图像视图占用图像所需的空间。
试试这个,这是一个图像,如果您希望您的布局在横向模式下应该可见,则必须为横向模式制作另一个布局或将视图保持在纵向模式下。
<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>