2016-08-04 50 views
0

UPDATE 2Wie kann ich meine TableLayouts auf das Zentrum ausrichten?

Die horizontalscrollview verwanzt ist, schneidet es Teil der Tabelle.

Dies ist die erste Tabelle, die Scrollview bewegt sich nicht und schneidet die erste Zelle.

enter image description here

Die zweite Tabelle hat Scroll aber die Grenzen sind falsch ... Scrolled max nach rechts.

enter image description here

Scrolled max auf der linken Seite hinterlässt einen leeren Raum.

enter image description here

Update 3

das genau das Layout auf ein anderes ähnliches Fragment kopiert und in die Mitte nicht ausrichten, aber die horizontalScroll funktioniert gut. Diese Zufälligkeit bringt mich um.

Die aktualisierte Layout:

<FrameLayout 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" 
tools:context="acr.acr_app.MyFragment3"> 
<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/scrollView3" > 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="top|center"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/textCompresores" 
       android:textSize="30dp" 
       android:textStyle="bold" 
       android:typeface="sans" 
       android:id="@+id/textView12" 
       android:layout_margin="30dp" 
       android:stretchColumns="60dp"/> 
     </LinearLayout> 

     <Spinner 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/spinner1" 
      android:layout_marginBottom="10dp" 
      android:textStyle="bold" 
      android:textAlignment="center"> 
     </Spinner> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center"> 

      <HorizontalScrollView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scrollbars="none" 
       android:fillViewport="true"> 
       <TableLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal|top" 
        android:stretchColumns="*" 
        android:id="@+id/tableLayout1"> 
       </TableLayout> 
      </HorizontalScrollView> 

      <HorizontalScrollView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scrollbars="none" 
       android:fillViewport="true"> 
       <TableLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal|top" 
        android:stretchColumns="*" 
        android:id="@+id/tableLayout2"> 
       </TableLayout> 
      </HorizontalScrollView> 
     </RelativeLayout> 
    </LinearLayout> 
</ScrollView> 

+0

Haben Sie mit _android versucht: layout_centerInParent = "true" _? – Piyush

+0

Probieren Sie es einfach mit dem gleichen Ergebnis aus, das horizontalScrollview funktioniert auch nicht richtig. Ich benutze das gleiche Layout für 4 Tabellen und das einzige, es funktioniert nicht, es ist das erste. – Xaloju

+0

also möchten Sie Ihre 'TableLayout' in der Mitte des Bildschirms richtig platzieren? Kann ich wissen, wie genau du willst? da Sie zwei 'TableLayout' in einem' HorizontalScrollView' haben, das in einem 'RelativeLayout' liegt ... können Sie eine Vorschau des Layouts zum besseren Verständnis zeigen ... – himanshu1496

Antwort

1

Sie dies versuchen:

<FrameLayout 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" 
tools:context="acr.acr_app.MyFragment3"> 
<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:id="@+id/scrollView3" > 

<LinearLayout 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="top|center"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/text" 
     android:textSize="30dp" 
     android:textStyle="bold" 
     android:typeface="sans" 
     android:id="@+id/textView12" 
     android:layout_margin="30dp" 
     android:stretchColumns="60dp"/> 
</LinearLayout> 

<Spinner 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/spinner1" 
    android:layout_marginBottom="10dp" 
    android:textStyle="bold" 
    android:textAlignment="center"> 
</Spinner> 

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center"> 

<HorizontalScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="none" 
     android:fillViewport="true"> 
      <TableLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal|top" 
       android:stretchColumns="*" 
       android:id="@+id/tableLayout1"> 
      </TableLayout> 
</HorizontalScrollView> 

<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="none" 
    android:fillViewport="true"> 
     <TableLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal|top" 
      android:stretchColumns="*" 
      android:id="@+id/tableLayout2"> 
     </TableLayout> 
</HorizontalScrollView> 

</RelativeLayout> 
</LinearLayout> 

In dem obigen Code habe ich die redundante LinearLayout entfernt, die seit wir waren Eltern von TableLayout sollte vermeiden, zu viele verschachtelte Layouts zu verwenden, wenn nicht wirklich notwendig, und ich habe decke d scrollView, damit das Kind in der Mitte platziert werden kann, wenn das Kind eine kleinere Breite als der Bildschirm hat. Bitte versuchen Sie es mit diesem Code und wenn es Probleme gibt, lassen Sie es mich bitte im Kommentarbereich wissen.