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