2017-11-03 3 views
0

Gibt es jemanden, der mir helfen kann, herauszufinden, was mit meinem Code nicht stimmt? Die Vorschau ist wie erwartet. aber Problem tritt auf, gerade als ich sie im realen Gerät prüfte. Ich fügte Admob Fahne Anzeige an der Unterseite hinzu. bevor es hinzugefügt wurde, war es völlig ok. Aber jetzt ist es nicht richtig ausgerichtet. Was ist mein Fehler oder was soll ich tun?Tastenausrichtung funktioniert nicht am echten Gerät Android

Mein XML-Code ist:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:background="#FFFFFF" 
android:orientation="vertical"> 

<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/scrollView8" 
    android:layout_alignParentTop="true" 
    android:layout_above="@+id/ll1" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="16dp" > 

     <TextView 
      android:id="@+id/textLink" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/description_product" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/result_field_product" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_alignWithParentIfMissing="true" 
      android:layout_centerInParent="false" 
      android:layout_marginTop="20dp" 
      android:gravity="center_vertical|center_horizontal" 
      android:text="Example application" 
      android:textSize="16sp" 
      android:textIsSelectable="true" /> 

    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:id="@+id/ll1" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_above="@+id/adView" 
    android:orientation="horizontal" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true"> 
    <Button 
     android:id="@+id/btnProceed" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/button_fullwidth" 
     android:padding="5dp" 
     android:text="@string/choose_action" 
     android:textColor="@android:color/white" /> 
    <view 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:visibility="invisible" 
     android:layout_weight="1"/> 

    <Button 
     android:id="@+id/btnCancel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/button_fullwidth" 
     android:padding="5dp" 
     android:text="@string/abort_action" 
     android:textColor="@android:color/white" /> 
</LinearLayout> 
<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:background="@color/colorAccent" 
    android:layout_alignParentBottom="true" 
    ads:adSize="BANNER" 
    ads:adUnitId="@string/banner_home_footer"> 
</com.google.android.gms.ads.AdView> 

Hier Meine eine Taste ausgerichtet ist, aber eine andere ist nicht, es ist place.How kann ich es beheben?

Aktueller Status: enter image description here

+0

Was wollen Sie mit Knopf ausrichten? – KeLiuyue

+0

Ich möchte nur btnProceed & btnCancel in der gleichen Zeile machen. –

+0

Konnten Sie das Bild zeigen, das Sie jetzt erhalten? – KeLiuyue

Antwort

1

1.Set der Inhalt android:gravity="center_vertical" im LinearLayout

2.make sicher, dass View ist gone oder invisible .Und Änderung View.

3.Wenn Sie möchten, dass das Layout mit zwei Tasten halbiert ist, sollten Sie android:layout_weight="1" und android:layout_width="0dp" in Button einstellen.

bearbeiten

Ändern Sie den Root-Tag zu LinearLayout

bereits.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:ads="http://schemas.android.com/apk/res-auto" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="#FFFFFF" 
       android:orientation="vertical"> 

    <ScrollView 
     android:id="@+id/scrollView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/ll1" 
     android:layout_weight="1" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="16dp"> 

      <TextView 
       android:id="@+id/textLink" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/description_product" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textSize="15sp"/> 

      <TextView 
       android:id="@+id/result_field_product" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:layout_alignWithParentIfMissing="true" 
       android:layout_centerInParent="false" 
       android:layout_marginTop="20dp" 
       android:gravity="center_vertical|center_horizontal" 
       android:text="Example application" 
       android:textIsSelectable="true" 
       android:textSize="16sp"/> 

     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/ll1" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:gravity="center_vertical" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/btnProceed" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/button_fullwidth" 
      android:padding="5dp" 
      android:text="@string/choose_action" 
      android:textColor="@android:color/white"/> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:visibility="invisible"/> 

     <Button 
      android:id="@+id/btnCancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/button_fullwidth" 
      android:padding="5dp" 
      android:text="@string/abort_action" 
      android:textColor="@android:color/white"/> 
    </LinearLayout> 

    <com.google.android.gms.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:background="@color/colorAccent" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_home_footer"> 
    </com.google.android.gms.ads.AdView> 
</LinearLayout> 
0

Jedes Mal, wenn Sie verwenden layout_weight Sie layout_width oder layout_height zu 0dp je nach orientation setzen soll.

Für z. wenn Sie android:orientation="horizontal" Verwendung android:layout_width="0dp"

und wenn Sie android:orientation="vertical" Verwendung android:layout_height="0dp"

haben
Verwandte Themen