2016-08-18 5 views
0

私は簡単な構成です。 Scrollview内のTextView、しかし私はそれが私が望むように動作させることはできません。Horizo​​ntalScrollViewのTextViewを右に設定します

私が今取得する問題。

  • TextViewのテキストを何も設定しなくても、TextViewが画面の幅より大きければ、ScrollViewは拡大されたままになります。
  • TextViewは左側にあります。

私は次のように得た:

 <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> 

私が欲しいもの。

  • 右側のTextView。
  • ScrollViewは、TextViewが画面の幅より大きい場合にのみ展開されます。

私は多くを試しましたが、私は正しいソリューションを見つけることができません。

誰かが私を助けてくれることを願っています!

+1

写真を追加しますか? –

+0

TextViewの幅を "wrap_content"に設定しようとしましたか? – Chris623

+0

体重を設定するか、Textviewのサイズを適切に設定します。現在のところ、TextViewはその親のLinearLayoutと同じサイズですが、ScrollView親のScrollViewと同じサイズです – VikingPingvin

答えて

0

私はあなたの問題を解決するには、2つの手掛かりを持って:

1)のLinearLayoutの向き垂直行い、その後、あなたは右

<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上のTextViewを配置することができます)のTextViewのwrap_contentを作る代わりに、 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

のTextView幅wrap_content

0

を作る私はハード、私はあなたの寸法を有するdid'tとして、後で自分の要件に従ってそれを変更することができますなどパディングおよびテキストサイズのようなものをコード化しています。

次のコードスニペットが役立つかどうかを確認してください。

<?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はあなたの問題を解決しましたか? – Nikhil

関連する問題