2016-08-18 2 views
0

Ich habe eine einfache Konstruktion; ein TextView in einer Scrollview, aber ich kann es nicht so machen, wie ich es will.TextView in HorizontalScrollView auf der rechten Seite setzen

Die Probleme, die ich jetzt bekomme;

  • Die Scrollview erweitert hält, wenn einmal die Textview größer war als die Breite des Bildschirms, auch wenn ich den Text von Textview zu nichts festgelegt.
  • Das TextView befindet sich auf der linken Seite.

Ich habe folgendes:

 <HorizontalScrollView 
      android:layout_weight="1" 

      android:layout_width="match_parent" 
      android:layout_height="match_parent" 

      android:fillViewport="true" 
      android:layout_gravity="right" 

      android:background="@drawable/background_scrollviews_display" 

      android:id="@+id/scrollViewSum"> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 

       android:layout_gravity="right"> 

       <TextView 
        style="@style/TextStyleDisplay" 
        android:textSize="@dimen/fontSizeTextViewSum" 

        android:paddingLeft="@dimen/paddingDisplayTextViews" 
        android:paddingRight="@dimen/paddingDisplayTextViews" 

        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_gravity="right" 
        android:gravity="right|center" 

        android:id="@+id/textViewSum"/> 

      </LinearLayout> 
     </HorizontalScrollView> 

Was ich will;

  • Das TextView auf der rechten Seite;
  • Die ScrollView wird nur erweitert, wenn TextView größer als die Breite des Bildschirms ist;

Ich habe viel versucht, aber ich kann einfach nicht die richtige Lösung finden.

Ich hoffe, jemand kann mir helfen!

+1

ein Bild hinzufügen was du willst? –

+0

haben Sie versucht, die Breite der TextView auf "wrap_content" zu setzen? – Chris623

+0

Legen Sie entweder ein Gewicht fest oder passen Sie Ihre Textansicht richtig an. Momentan hat TextView die gleiche Größe wie das übergeordnete LinearLayout, welches die selbe Größe hat wie das übergeordnete ScrollView – VikingPingvin

Antwort

0

Ich habe einen zwei Anhaltspunkt um Ihre Probleme zu lösen:

1) Linearlayout Ausrichtung Vertikal, machen, dann können Sie Textview auf der rechten

<LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 

      android:layout_gravity="right"> 

      <TextView 
       style="@style/TextStyleDisplay" 
       android:textSize="@dimen/fontSizeTextViewSum" 

       android:paddingLeft="@dimen/paddingDisplayTextViews" 
       android:paddingRight="@dimen/paddingDisplayTextViews" 

       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="right" 
       android:gravity="right|center" 

       android:id="@+id/textViewSum"/> 

     </LinearLayout> 

2) positionieren Textview wrap_content machen statt match_parent

<TextView 
       style="@style/TextStyleDisplay" 
       android:textSize="@dimen/fontSizeTextViewSum" 

       android:paddingLeft="@dimen/paddingDisplayTextViews" 
       android:paddingRight="@dimen/paddingDisplayTextViews" 

       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_gravity="right" 
       android:gravity="right|center" 

       android:id="@+id/textViewSum"/> 
0

machen die Textview-Breite wrap_content

0

Ich habe hart codierte Sachen wie Polsterung und Textgröße usw., wie ich Ihre Dimensionen did't, können Sie es später nach Ihren Wünschen ändern können.

Überprüfen Sie, ob der folgende Code Snipet hilft.

<?xml version="1.0" encoding="utf-8"?> 
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollViewSum" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textViewSum" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="right|center" 
      android:paddingLeft="15dp" 
      android:paddingRight="15dp" 
      android:text="ldksjfkdlfkfldksjfkdlfkf" 
      android:textSize="20sp" /> 
    </LinearLayout> 
</HorizontalScrollView> 
+0

@tomhogenkamp ist dein Problem gelöst? – Nikhil

Verwandte Themen