Ich erstelle einen Bildschirm, um PIN-Nummern einzugeben. Ich habe ein vertikales lineares Layout verwendet. Innerhalb dieses linearen Layouts habe ich 4 horizontale lineare Layouts erstellt. In diesen linearen Layouts habe ich Schaltflächen als feste Breite und Höhe. Bei gleicher Schriftgröße des Schaltflächentextes wird diese gut angezeigt, aber wenn ich die Schriftgröße der letzten beiden Schaltflächen verkleinere, werden diese beiden Schaltflächen innerhalb des horizontalen linearen Layouts abgeschnitten. Bitte sehen Sie sich den Screenshot zur besseren Erklärung an.LinearLayout nicht wrapping Tastenansichten unterschiedlicher Schriftgröße
With different button font sizes
With same button font sizes (40sp)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
style="@style/RootLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/actionbar_login"/>
<TextView
style="@style/TextViewLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:text="@string/welcome"/>
<TextView
style="@style/TextViewNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="@string/enter_pin"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:orientation="horizontal">
<View
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginRight="20dp"
android:background="@drawable/circle_gray"/>
<View
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginRight="20dp"
android:background="@drawable/circle_gray"/>
<View
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginRight="20dp"
android:background="@drawable/circle_gray"/>
<View
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginRight="20dp"
android:background="@drawable/circle_gray"/>
<View
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginRight="20dp"
android:background="@drawable/circle_gray"/>
<View
android:layout_width="15dp"
android:layout_height="15dp"
android:background="@drawable/circle_gray"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_1"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_2"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_3"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_4"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_5"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_6"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_7"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_8"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_9"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="0"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:background="@drawable/selector_pin_button"
android:text="@string/_0"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/selector_pin_button"
android:text="0"
android:textColor="@drawable/selector_pin_button_text"
android:textSize="40sp"/>
</LinearLayout>
</LinearLayout>
Zahlen sind eine Ziffer und Buchstaben sind 6 und mehr Ziffern –
Dann sollte es den Text innerhalb von 70dp Breite und Höhe halten, warum es gesamte Taste nach unten bewegt? –
Das lineare Layout ist Wrap-Inhalt. Wenn es Tasten nach unten bewegt, sollte es zumindest keine Tasten abschneiden. –