在右侧的HorizontalScrollView中设置TextView

汤姆根坎普

我的结构很简单。滚动视图中的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;
  • 仅当TextView大于屏幕宽度时,ScrollView才会展开;

我做了很多尝试,但是我根本找不到正确的解决方案。

我希望有人能帮助我!

安德夫

我有两条线索可以解决您的问题:

1)将LinearLayout方向设置为Vertical,然后可以将TextView定位在右侧

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章