我將在 a 中并排制作imageViewand 。它在設計時看起來不錯,但在我運行該應用程式時表現得很奇怪。textViewcardView
我的item_offer_list.xml檔案如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@ id/cv_iv_photo_poster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="null"
tools:src="@drawable/ic_launcher_background" />
<TextView
android:id="@ id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_toEndOf="@ id/cv_iv_photo_poster"
android:gravity="center"
android:text="@string/app_name">
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
我在回收站視圖中使用了上面的設計,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".OfferWallListFragment">
<LinearLayout
android:id="@ id/llRecyclerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
android:orientation="horizontal">
<ProgressBar
android:id="@ id/pbLoadingItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
<TextView
android:id="@ id/txtNoConnection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:visibility="gone"
tools:text="No Internet Connection" />
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/rv_OfferData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:visibility="visible"
tools:listitem="@layout/item_offer_list">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我的設計看起來不錯,如下所示:

但是當我在模擬器中運行應用程式時,我的影像非常大,但覆寫了所有空間,如下所示:

我不知道為什么會這樣?如果有任何想法,請調查一下。
uj5u.com熱心網友回復:
我假設您正在從 Internet 下載影像。也許您忘記ImaveView在您的item_offer_list.xml?
我的意思不是這個:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
嘗試這樣的事情:
android:layout_width="60dp"
android:layout_height="60dp"
或者你自己的尺寸而不是60dp
uj5u.com熱心網友回復:
在這里你有兩個選擇:
- 首先,您可以調整位圖影像的大小,然后進行設定。
int 最大高度 = 2000; int 最大寬度 = 2000;
float scale = Math.min(((float)maxHeight / bitmap.getWidth()), ((float)maxWidth / bitmap.getHeight()));
矩陣matrix = new Matrix(); matrix.postScale(規模,規模);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
- 利用
android:layout_width="wrap_content" android:layout_height="wrap_content"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/534425.html
標籤:爪哇安卓XML安卓工作室
