2016-03-27 90 views
0

我在這裏看到了很多關於這個問題的答案,但沒有一個真正爲我工作(唯一的例外是底部填充,我認爲這是一個醜陋的解決方法)。ScrollView被底部按鈕欄截斷

我在Fragment裏面的LinearLayout裏面有一個ScrollView。內容的最後一行(或左右)不能被看到,因爲它隱藏在按鈕後面。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment" 
android:orientation="vertical"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/section_label" 
    android:layout_weight="0" 
    android:layout_gravity="center_horizontal" /> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:id="@+id/scrollView" 
    android:layout_weight="1"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/listLayout"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/textView" 
       android:width="0px" 
       android:layout_weight="0.8" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/textView2" 
       android:width="0px" 
       android:layout_weight="0.2" /> 
     </TableRow> 

    </LinearLayout> 
</ScrollView> 

</LinearLayout> 

此問題仍然存在,如果我刪除「中文字」 TextView的,所以這不是導致它的視圖。我曾嘗試設置不同的layout_heights和layout_weights,所有視圖都應該伸展,但目前爲止我還沒有運氣。

Demonstration of the issue described, all the items are supposed to be doubled

+0

嗯,什麼'按鈕'?爲什麼你有沒有'TableLayout'的'TableRow'? – Sourabh

+0

我的意思是android軟件按鈕。 'TableLayout'沒有改變任何東西。 – Majlen

+0

如果你擔心底部填充使用常量,你可以像這樣以編程方式設置底部填充:http://stackoverflow.com/questions/8689117/dimension-of-soft-buttons-bar – Gi0rgi0s

回答

0

即使不是完美的,這工作對我來說是將此代碼添加到的FragmentonCreateView()方法的解決方案:爲指向我的狀態欄高度方向

int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); 
if (resourceId > 0) { 
    statusBarHeight = getResources().getDimensionPixelSize(resourceId); 
    density = Math.ceil(getResources().getDisplayMetrics().density); 
    realStatusBarHeight = (int) Math.ceil(statusBarHeight * density); 
} 
ScrollView scroll = (ScrollView) rootView.findViewById(R.id.scrollView); 
scroll.setPadding(scroll.getPaddingLeft(), scroll.getPaddingTop(), scroll.getPaddingRight(), scroll.getPaddingBottom() + realStatusBarHeight); 

感謝@ Gi0rgi0s。

1

設置機器人:fillViewport =上滾動型

「真」
+0

沒有任何改變。 – Majlen

0

使用它,並選中。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment" 
android:orientation="vertical"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/section_label" 
    android:layout_weight="0" 
    android:layout_gravity="center_horizontal" /> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:id="@+id/scrollView" 
    android:layout_weight="1"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/listLayout"> 

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

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/textView" 
       android:layout_weight="0.5" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/textView2" 
       android:layout_weight="0.5" /> 
     </LinearLayout> 

    </LinearLayout> 
</ScrollView> 

</LinearLayout> 

我希望它能幫助你。

+0

不幸的是它仍然表現相同。最後一項無法看到。我想知道我是否在做可怕的錯誤... – Majlen

+0

@Majlen我改變了代碼,檢查它。如果您再次遇到問題,請告知更多詳情或按照圖片顯示。 –

+0

我在原帖中添加了一個示例。 LinearLayout以編程方式填充。現在,我已經創建了一個帶有LinearLayout而不是TableRow的靜態示例,因爲您的代碼中存在最後2個TextView包含不同消息的情況,因此可以看到它。問題仍然存在,可以在這張圖片中看到:http://home.zcu.cz/~majlen/issue.png。 – Majlen