2016-12-22 42 views
0

我是新來的android編程。我正在實現一個簡單的計算器,我正面臨水平滾動視圖的問題。我正在使用水平滾動視圖中的編輯文本。它第一次工作完全正常,但一旦我清除了屏幕,它仍然保持滾動限制,這意味着即使屏幕上的數字很少,我也能夠滾動更多。我想實現的是限制它的滾動。以下是屏幕截圖和XML代碼。水平滾動查看,滾動發佈Android

First Time

[第二時間] [2]

It is still scroll-able even though there are few digits

<HorizontalScrollView 
     android:id="@+id/hsvMain" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end" 
     android:scrollbars="none" 
    > 

     <EditText 

      android:id="@+id/mainEditText" 
      android:paddingTop="10dp" 
      android:paddingRight="2dp" 
      android:background="#ffff" 
      android:ellipsize="end" 
      android:focusable="false" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="55sp" 

      android:textStyle="bold" 

      /> 

    </HorizontalScrollView> 
+0

嘗試設置編輯文本layout_width @ height to wrap_content –

回答

0

嘗試改變圓形佈局的高度/寬度的屬性,使HorizontalScrollViewlayout_width="fill_parent"EditTextlayout_width="wrap_content"layout_height="wrap_content"

<HorizontalScrollView 
     android:id="@+id/hsvMain" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end" 
     android:scrollbars="none"> 

     <EditText 
      android:id="@+id/mainEditText" 
      android:paddingTop="10dp" 
      android:paddingRight="2dp" 
      android:background="#ffff" 
      android:ellipsize="end" 
      android:focusable="false" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="55sp" 
      android:textStyle="bold"/> 

</HorizontalScrollView> 

編輯

爲什麼,因爲你說的是​​scrollview包裹內容EditText無論大小不前工作的原因,所以它只會在EditText左右滾動。但是,如果您將ScrollView指定爲match_parent,它將始終是屏幕的寬度,然後可以在父級(ScrollView)內滾動EditText,無論大小如何。

注意:使用match_parent而不是fill_parent,fill_parent已被棄用。 (雖然仍然有效)

+0

非常感謝:)你能解釋一下它爲什麼要這樣做,以前有什麼錯誤嗎?再次感謝很多 –

+0

很高興幫助你。 –