我有以下xml以顯示圖像。問題是,當頁面加載時,圖像視圖矩形不是按照給定的大小。我該如何糾正它?例如,我需要一個150 x 150矩形的代碼。儘管參數正確,但仍顯示不正確的圖像視圖大小
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="2dp"
android:id="@+id/table_two">
<TableRow
android:padding="2dp"
android:layout_width="150dp"
android:layout_height="150dp">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_weight="1"
app:srcCompat="@android:drawable/picture_frame"
android:id="@+id/ui_imageView_browse"
android:layout_gravity="center"
android:scaleType="fitXY" />
</TableRow>
</TableLayout>
</LinearLayout>
請注意。檢查https://stackoverflow.com/questions/9476662/how-to-set-android-layout-to-support-all-screen-sizes – user8256287
@JaysonJohn,它講述了不同屏幕尺寸的解決方案。我的問題是關於每個代碼的固定大小的矩形,而不考慮屏幕大小或設備。它的工作原理是 – djac