0
<ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/btnAddRow" 
     android:layout_below="@id/llInventoryViewHeader" 
     android:isScrollContainer="true" 
     android:scrollbars="vertical" > 

     <LinearLayout 
      android:id="@+id/llDynamicView" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 
     </LinearLayout> 
    </ScrollView> 

代碼,其設置在線性佈局行: -鍵盤隱藏的EditText內滾動視圖

/** 
    * Set Edit text 
    */ 
    private void setUsedList() { 

     for (final InventoryResource inventoryResource : mCurrentUsedResourceList) { 
      final LinearLayout LL = new LinearLayout(InventoryActivity.this); 
      LL.setOrientation(LinearLayout.HORIZONTAL); 

      final LayoutParams LLParams = new LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 

      LL.setWeightSum(10f); 
      LL.setLayoutParams(LLParams); 

      // ResourceName Params 
      final LinearLayout.LayoutParams resourceViewParams = new LinearLayout.LayoutParams(
        0, LinearLayout.LayoutParams.WRAP_CONTENT); 
      resourceViewParams.weight = 6f; 
      resourceViewParams.setMargins(5, 5, 5, 5); 

      // Resource Edittext 
      final EditText edtTextResourceName = new EditText(
        InventoryActivity.this); 
      edtTextResourceName.setGravity(Gravity.CENTER); 
      edtTextResourceName.setLayoutParams(resourceViewParams); 
      edtTextResourceName.setInputType(InputType.TYPE_CLASS_TEXT); 
      edtTextResourceName.setTextColor(Color.BLACK); 
      edtTextResourceName.setTextSize(16f); 
      edtTextResourceName.setBackground(getResources().getDrawable(
        R.drawable.box_edt_values)); 

      // Amount Params 
      final LinearLayout.LayoutParams amtViewParams = new LinearLayout.LayoutParams(
        0, LinearLayout.LayoutParams.WRAP_CONTENT); 
      amtViewParams.weight = 2f; 
      amtViewParams.setMargins(5, 5, 5, 5); 

      final EditText edtTextConstructorAmt = new EditText(
        InventoryActivity.this); 
      edtTextConstructorAmt.setGravity(Gravity.CENTER); 
      edtTextConstructorAmt.setInputType(InputType.TYPE_CLASS_PHONE); 
      edtTextConstructorAmt.setLayoutParams(amtViewParams); 
      edtTextConstructorAmt.setTextColor(Color.BLACK); 
      edtTextConstructorAmt.setTextSize(16f); 
      edtTextConstructorAmt.setBackground(getResources().getDrawable(
        R.drawable.box_edt_values)); 


      final EditText edtTextInspectorAmt = new EditText(
        InventoryActivity.this); 
      edtTextInspectorAmt.setInputType(InputType.TYPE_CLASS_PHONE); 
      edtTextInspectorAmt.setGravity(Gravity.CENTER); 
      edtTextInspectorAmt.setLayoutParams(amtViewParams); 
      edtTextInspectorAmt.setTextColor(Color.BLACK); 
      edtTextInspectorAmt.setTextSize(16f); 
      edtTextInspectorAmt.setBackground(getResources().getDrawable(
        R.drawable.box_edt_values)); 

      final InventoryPojo pojo = new InventoryPojo(); 
      pojo.id = inventoryResource.getOrderNum(); 
      mOrderNumber += 1; 
      pojo.edtResourceName = edtTextResourceName; 
      pojo.edtConstructoreAmt = edtTextConstructorAmt; 
      pojo.edtInspectoreAmt = edtTextInspectorAmt; 
      mUsedList.add(pojo); 

      if (mPreference.getString(Preferences.LAN_CULTURE, 
        Constants.CULTURE_HEBREW).equalsIgnoreCase(
        Constants.CULTURE_ENGLISH)) { 
       LL.addView(edtTextResourceName); 
       LL.addView(edtTextConstructorAmt); 
       LL.addView(edtTextInspectorAmt); 
       mLLDetails.addView(LL); 
       mLLDetails.invalidate(); 
      } else { 
       LL.addView(edtTextInspectorAmt); 
       LL.addView(edtTextConstructorAmt); 
       LL.addView(edtTextResourceName); 
       mLLDetails.addView(LL); 
       mLLDetails.invalidate(); 
      } 
     } 
    } 

代碼: -

parent = (RelativeLayout)findViewById(R.id.rlParent); 

parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){ 
      public void onGlobalLayout(){ 
        int heightDiff = parent.getRootView().getHeight()- parent.getHeight(); 
        // IF height diff is more then 150, consider keyboard as visible. 
        if(heightDiff > 150){ 
         // Its keyboard mostly 
         parent.setPadding(0, 0, 0, heightDiff); 
        } 
        else if(heightDiff < 150){ 
         // Keyboard goes away, readjust 
         parent.setPadding(0, 0, 0, 0); 
        } 
       } 
     }); 

我有在其內部被添加動態行滾動視圖。我面臨的問題是,如果我的觀點有10行,那麼當我開始輸入時,它不會滾動到最後。對於例如在10行的情況下,我可以滾動到7行,然後其他3行是不可見的,必須按下鍵盤關閉鍵盤,然後我可以將值添加到休息3行。

我已經添加了inputMode來調整我的清單中的活動,並且還添加了android:isScrollContainer =「true」,但仍然不起作用。

任何人有任何想法如何解決它。

+0

嘗試把機器人:windowSoftInputMode = 「stateVisible | adjustResize」 這個屬性的活性起着其中包含了這一觀點。 – Techfist 2014-09-04 08:52:23

+0

@Techfist不在這方面工作。不知道爲什麼它不工作 – Scorpion 2014-09-04 09:16:39

+0

有一個可以幫助你的結構,這是最後的手段,我猜如果默認參數不工作最有可能這是從Android端破壞。你能不能把你的代碼放在一邊,這樣我可以幫你解決問題? – Techfist 2014-09-04 10:22:11

回答

2

好了,試試這個也許會救你的事業,

  1. 首次在持有該滾動視圖給identefier其根源即其父你的主要XML

  2. 其次,android會爲您提供一個API,告訴您它在繪製之前分配給它們的視圖的尺寸,您可以通過ViewTreeObservers

  3. 使用此代碼檢查鍵盤是否充氣,充氣時,您可以將填充底部的高度差分配給您的父視圖,並且當鍵盤消失時只需重置填充集。這將確保您可以滾動隱藏在充氣鍵盤下面的所有視圖。

    parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){ 
        public void onGlobalLayout(){ 
         int heightDiff = parent.getRootView().getHeight()- parent.getHeight(); 
         // IF height diff is more then 150, consider keyboard as visible. 
         if(heightDiff > 150){ 
          // Its keyboard mostly 
          parent.setPadding(0, 0, 0, heightDiff); 
         } 
         else if(heightDiff < 150){ 
          // Keyboard goes away, readjust 
          parent.setPadding(0, 0, 0, 0); 
         } 
        } 
    }); 
    

4確保你已經在你的活動定義在manifiest文件這個參數

android:windowSoftInputMode="adjustResize" 
+0

我試過這個,但它不工作。我正在使用我的根相對佈局作爲它的父項。 – Scorpion 2014-09-05 08:37:15

+0

你可以把你的代碼放在這裏? – Techfist 2014-09-05 08:58:01

+0

添加了代碼。請注意,我的父母是XML佈局的根父級。我的想法是,我們需要找出鍵盤是否打開,如果它打開,則不僅需要設置底部填充,以便可以看到項目。但不知何故,它無法弄清楚該鍵盤是否打開。 – Scorpion 2014-09-05 09:02:49

0

你的滾動視圖似乎很好。 爲了做滾動,你只需要在你最有趣的文件的活動中添加單行。

機器人:windowSoftInputMode =「adjustResize」

+0

我做到了這一點,但它沒有幫助我。它在添加adjustResize或adjustpan之後不滾動。 – Scorpion 2014-09-04 09:14:05

+0

我可以顯示你的代碼嗎? – Jatin 2014-09-04 09:26:42