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> 

Code which set rows in linear layout :-

/** * 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(); } } } 

Code :-

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); } } }); 

I am having scroll view inside which dynamically rows are being added. The problem i am facing is that if my view is having 10 rows then when i start typing it won't scroll upto end. For e.g. in case of 10 rows I am able to scroll up to 7 row and then other 3 rows are not visible and have to close the keyboard by pressing back and then i can add the value to rest 3 row.

I have added inputMode to adjustPan in my manifest for the activity and also added android:isScrollContainer="true" but still its not working.

Anyone having any idea how to resolve it.

5
  • try putting android:windowSoftInputMode="stateVisible|adjustResize" this attribute in avtivity which contains this view. Commented Sep 4, 2014 at 8:52
  • @Techfist not working in this as well. Don't know why its not working Commented Sep 4, 2014 at 9:16
  • there is one soulution which can help you, it is last resort i guess as if default parameters are not working most probably this is broke from android end. can you put your code as well, so that I can help you out with? Commented Sep 4, 2014 at 10:22
  • @Techfist thanks for your kind response, i have added code snippet. Commented Sep 4, 2014 at 11:13
  • Alright scorpion, am posting my answer below, but be sure as in your case automatic readjustment of size is not taking place, hence am providing you an alternate solution, but be careful as in the device where automatic readjust do work, you might face some issue.but there are workaround for that as well.. Commented Sep 4, 2014 at 11:33

3 Answers 3

2

Okay, try this it might save your cause,

  1. first in your main XML which holds this Scroll view give identefier to its root i.e its parent

  2. Second, android does provide you an API which tell you about dimensions of its view which are assigned to them right before they are drawn, this you can read through ViewTreeObservers

  3. use this code to check when keyboard is inflated, when its inflated, you can assign the height differece as padding bottom to your parent view, and when keyboard goes away just reset the padding set. this will make sure you can scroll all view which are hidden beneath inflated keyboad.

    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 make sure you have this parameter defined in you activity in manifiest file

android:windowSoftInputMode="adjustResize" 
Sign up to request clarification or add additional context in comments.

2 Comments

I tried this but its not working. I am using my root Relative layout as parent for this.
Added the code. Please note that my parent is the root parent of the XML layout. I got your idea that we need to find out that keyboard is open or not and if its open than just need to set the bottom padding so items can be visible. But somehow its not able to figure out that keyboard is open or not.
1

You might want to play around with the windowSoftInputMode. And here's an interesting discussion that helped me solve my similar problem.

Hope this helps you!

Comments

0

Your scrollview seems to be fine. For doing scroll you just have to add single line inside your activity of manifiest file.

android:windowSoftInputMode="adjustResize"

1 Comment

I did this but its not helping me. Its not scrolling after adding adjustResize or adjustpan both.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.