[英]set TextView in HorizontalScrollView to the right
我的結構很簡單。 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寬度wrap_content
我有一些硬編碼的內容,例如填充和文本大小等。由於我沒有您的尺寸,您可以稍后根據需要進行更改。
檢查以下代碼片段是否有幫助。
<?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>
我有兩條線索可以解決您的問題:
1)使LinearLayout方向垂直,然后可以將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"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.