第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

android studio 如何根據(jù)不同的屏幕尺寸自動調(diào)整imageview的大小?

我開始使用 Android Studio 為 Android 設(shè)備開發(fā)應(yīng)用程序。當我測試我的應(yīng)用程序的屏幕尺寸兼容性時,我注意到圖像視圖不會自動調(diào)整大小。圖像視圖的位置在不同的屏幕尺寸下看起來完全不同。如果屏幕足夠小,圖像視圖有時會被放置在視域之外。我查遍了互聯(lián)網(wǎng),但我對如何使應(yīng)用程序與大多數(shù)屏幕尺寸(不包括平板電腦)兼容感到有點困惑。我去了android網(wǎng)站,他們說使用wrap_content。但如果我使用它,我將無法根據(jù)我想要的方式調(diào)整圖像視圖的高度和寬度。有誰知道如何使 imageview 根據(jù)屏幕尺寸自動調(diào)整大?。恳韵率钦诎l(fā)生的事情的圖片:這是應(yīng)用程序的布局:這就是我想要的樣子(Pixel 3):但這是它在較小屏幕(Nexus 5)中的樣子:Xcode 中有一個稱為自動調(diào)整大小的功能,可以自動調(diào)整內(nèi)容的大小。android studio 有類似的東西嗎?
查看完整描述

3 回答

?
MYYA

TA貢獻1868條經(jīng)驗 獲得超4個贊

圖像視圖不會自動調(diào)整大小

因為您使用的是固定大小值,所以imageView您遇到了以下問題:

不同的手機有不同的屏幕尺寸,在您的布局中,您在視圖上使用固定尺寸(240dp例如固定尺寸),結(jié)果是在一個屏幕(您的 android studio 預(yù)覽屏幕)上看起來不錯的內(nèi)容在另一個屏幕上看起來不太好屏幕(您的實際手機)。


怎么修

您可以使用這些屬性來使圖像的大小響應(yīng):

app:layout_constraintHeight_percent="0.25"
app:layout_constraintWidth_percent="0.25"

您需要0dpandroid:layout_width和 中給出圖像尺寸android:layout_height

我所做的是根據(jù)屏幕尺寸告訴視圖的寬度和高度相等25%,這將使您的視圖響應(yīng)所有屏幕尺寸,因此它將“自動調(diào)整大小”


查看完整回答
反對 回復(fù) 2023-10-13
?
富國滬深

TA貢獻1790條經(jīng)驗 獲得超9個贊

更新


根據(jù)@tamir-abutbul的回答,使用layout_constraintHeight_percent和layout_constraintWidth_percent使視圖根據(jù)屏幕尺寸適合是一個很好的解決方法。我已將頂部項目放置在網(wǎng)格布局中,您可以將其應(yīng)用于您正在使用的任何頂部布局,主要要考慮的是此處的layout_constraintHeight/Width_percent。另外,對于圖像,我已將背景設(shè)置為透明并將scaleType更改為“fitCenter”,以便圖像在任何屏幕上保持其縱橫比。希望這可以幫助。您可以將 android 更改為 androidx。


<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity"

>


<GridLayout

    android:id="@+id/gridLayout"

    android:layout_width="match_parent"

    android:layout_height="0dp"

    android:layout_marginTop="0dp"

    android:background="#faf"

    android:columnCount="5"

    android:rowCount="4"

    app:layout_constraintHeight_percent="0.4"

    app:layout_constraintTop_toTopOf="parent">



</GridLayout>


<ImageView


    android:id="@+id/imageView3"

    android:layout_width="0dp"

    android:layout_height="0dp"

    android:layout_marginTop="8dp"

    android:background="#00000000"

    android:scaleType="fitCenter"

    android:src="@drawable/lamborghini"

    app:layout_constraintBottom_toBottomOf="parent"

    app:layout_constraintEnd_toEndOf="parent"

    app:layout_constraintHeight_percent="0.30"

    app:layout_constraintHorizontal_bias="0.495"

    app:layout_constraintStart_toStartOf="parent"

    app:layout_constraintTop_toBottomOf="@+id/gridLayout"

    app:layout_constraintVertical_bias="0.265"

    app:layout_constraintWidth_percent="0.7" />


<Button

    android:id="@+id/resetButton"

    style="@style/Widget.AppCompat.Button.Borderless.Colored"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_marginStart="16dp"

    android:layout_marginTop="8dp"

    android:layout_marginBottom="16dp"

    android:background="#F70000"

    android:text="Undo"

    android:textColor="#000000"

    android:textSize="20sp"

    app:layout_constraintBottom_toBottomOf="parent"

    app:layout_constraintStart_toStartOf="parent"

    app:layout_constraintTop_toBottomOf="@+id/imageView3"

    app:layout_constraintVertical_bias="0.395" />





 </android.support.constraint.ConstraintLayout> 


查看完整回答
反對 回復(fù) 2023-10-13
?
慕少森

TA貢獻2019條經(jīng)驗 獲得超9個贊

你的圖像視圖就像這樣,因為你在其他視圖中定義的寬度和高度很大,所以也許你可以嘗試這個庫在其他屏幕中具有相同的尺寸

https://github.com/intuit/sdp


查看完整回答
反對 回復(fù) 2023-10-13
  • 3 回答
  • 0 關(guān)注
  • 270 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號