簡體   English   中英

我想水平放置五個圖像按鈕,但是在某些設備上我只能得到四個按鈕

[英]I want to place five imagebuttons horizontally, but when I do I only get 4 buttons in some devices

有沒有辦法可以在同一列中看到所有5個ImageButton? 我正在使用計算器應用程序,它有5列和6行。 即使某些設備上有5個按鈕,但小型設備上的屏幕上並未顯示所有按鈕。 有什么可行的方法嗎? 這是我正在處理的xml。

<LinearLayout 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"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/txtStack"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="3sp"
        android:gravity="right"
        android:text="txt stack"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/txtInput"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="5sp"
        android:gravity="right"
        android:text="text input"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/txtMemory"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="5sp"
        android:gravity="left"
        android:text="for memory"
        android:textSize="15sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_mc" />


        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_mr" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_ms" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_m_plus" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_m_minus" />
    </LinearLayout>

</LinearLayout>

如果將5張圖像水平放置,可能會在屏幕上跑出1張。 如果您有此問題,建議將圖像放在滾動視圖中。

通過以下方式使用體重

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:weightSum="5"  >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_mc"
            android:layout_weight="1" />


        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_mr"
            android:layout_weight="1"/>

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_ms"
            android:layout_weight="1" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_m_plus"
            android:layout_weight="1" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button_m_minus"
            android:layout_weight="1" />
    </LinearLayout>

希望這行得通

暫無
暫無

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

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