Android - 将图像缩放到可用 space
Android - scale image to available space
我熟悉 Windows Phone XAML 及其带行和列的网格。现在我想开发一个具有类似布局的 Android 应用程序:
______________________
| |
| |
| 1' row - two images |
| |
| |
| |
| |
|----------------------|
| 2' row - TextView |
| |
|----------------------|
| 3' row - two buttons |
|______________________|
使用 GridRows 在 XAML 中很容易获得这种布局。第一行 Height="*"
。第二行和最后一行 Height="Auto"
。我怎样才能在 Android 中得到这个?我试过 TableLayout,它在大屏幕上运行良好。但是在小屏幕上我只能看到没有按钮的第一行和第二行。按钮和文本应始终可见,图像应适合可用屏幕的其余部分 space。图像是透明的,一个加载另一个。感谢您的任何提示。
使用线性布局。对于第一项,设置其 layout_height="0dp" 和 layout_weight="1"。对于另外两个,输入 layout_height="wrap_content"。这将为底部的 2 个元素提供所需的空间,但不会更多,并根据权重比例将剩余量分配给所有 0dp 高度。由于只有 1 件物品有重量,所以它会全部放在那里。
这是截取的 xml 代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<!--add two images here-->
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--add two buttons here-->
</RelativeLayout>
</LinearLayout>
我熟悉 Windows Phone XAML 及其带行和列的网格。现在我想开发一个具有类似布局的 Android 应用程序:
______________________
| |
| |
| 1' row - two images |
| |
| |
| |
| |
|----------------------|
| 2' row - TextView |
| |
|----------------------|
| 3' row - two buttons |
|______________________|
使用 GridRows 在 XAML 中很容易获得这种布局。第一行 Height="*"
。第二行和最后一行 Height="Auto"
。我怎样才能在 Android 中得到这个?我试过 TableLayout,它在大屏幕上运行良好。但是在小屏幕上我只能看到没有按钮的第一行和第二行。按钮和文本应始终可见,图像应适合可用屏幕的其余部分 space。图像是透明的,一个加载另一个。感谢您的任何提示。
使用线性布局。对于第一项,设置其 layout_height="0dp" 和 layout_weight="1"。对于另外两个,输入 layout_height="wrap_content"。这将为底部的 2 个元素提供所需的空间,但不会更多,并根据权重比例将剩余量分配给所有 0dp 高度。由于只有 1 件物品有重量,所以它会全部放在那里。
这是截取的 xml 代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<!--add two images here-->
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--add two buttons here-->
</RelativeLayout>
</LinearLayout>