如果屏幕足夠大,我需要一個ScrollView顯示內容,否則它應該顯示滾動。如何解決與包含一個孩子的ScrollView錯誤layout_gravity =「center」
這裏是我用於測試
<ScrollView
android:id="@+id/maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/admob"
android:layout_below="@id/app_bar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abc1\nabc2\nabc3\nabc4\nabc5\nabc6\nabc7\nabc8\nabc9\nabc10\nabc11\nabc12\nabc13\nabc14\nabc15\nabc16\nabc17\nabc18\nabc19\nabc20\nabc21"
android:textSize="35sp"
android:textStyle="bold"/>
</LinearLayout>
</ScrollView>
我的應用程序需要在滾動視圖以顯示來自ABC1到abc21示例代碼。但相反,它顯示從abc 5到abc21與額外的底部空間。檢查屏幕截圖如下攻擊:
這裏是ABC5而不是ABC1開始畫面顯示的TextView:
這裏是顯示以下文本視圖額外的空間圖片:
額外的空間措施正確的文本視圖中缺少的部分,也只有當滾動需要發生時刪除問題(即如果內容適合在屏幕上,當不需要滾動 - 他們是在問題,當co內容更多,需要滾動然後問題出現)。
更新1: - 增加了一些風景圖片
頂 額外的空間 末
更新2:一旦我刪除d layout_gravity =「center」問題解決了,但是我需要那個屬性。由於我的內容是動態的,當需要顯示小內容時,它應該顯示在中心而不是頂部(當我刪除該屬性時會發生這種情況),並且內容很大時需要顯示滾動條。