簡體   English   中英

如何讓按鈕適應 Android Studio 中的任何屏幕尺寸

[英]How do I get Buttons to adapt to any screen size in Android Studio

所以我想要一個 ImageView,它是一個語音氣泡和一個按鈕,它是我活動中的企鵝。 企鵝按鈕應該在右下角,語音氣泡 ImageView 應該在企鵝上方的左邊一點點。 當我將所有寬度和高度設置為固定值時,它工作正常,但是一旦我在另一台設備上打開它,它就會全部調整大小。 我的問題是我找不到任何方法讓這些元素按照我想要的方式適應不同的屏幕尺寸。 下面是一些代碼,它確實在每個設備上調整了它們的大小,但它調整了 50/50,因此 ImageView 占據了上屏的 50%,而按鈕占據了下屏的 50%。 我不知道如何將它們保留在某個 position 中,同時仍在不同屏幕上調整大小。 歡迎任何幫助。

   <LinearLayout
    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"
    android:orientation="vertical"
    android:background="@drawable/ein_hintergrund2"
    tools:context=".MainActivity">
<ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        app:srcCompat="@drawable/speechbubble"
        android:id="@+id/klick_textView"
        android:layout_marginBottom="9dp"
        android:contentDescription="@string/todo"/>
<Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/start_button"
        android:background="@drawable/pinguin"/> </LinearLayout>

由於它有點復雜,我會根據不同的屏幕尺寸使用不同的布局 go。 或者如果是風景等。

我建議看看 這個頁面

您應該查看ConstraintLayout它會幫助您在大多數情況下根據設備/屏幕具有類似的布局。

你可以找到一個代碼實驗室來幫助你 go 雖然它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM