<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」,但仍然不起作用。
任何人有任何想法如何解決它。
嘗試把機器人:windowSoftInputMode = 「stateVisible | adjustResize」 這個屬性的活性起着其中包含了這一觀點。 – Techfist 2014-09-04 08:52:23
@Techfist不在這方面工作。不知道爲什麼它不工作 – Scorpion 2014-09-04 09:16:39
有一個可以幫助你的結構,這是最後的手段,我猜如果默認參數不工作最有可能這是從Android端破壞。你能不能把你的代碼放在一邊,這樣我可以幫你解決問題? – Techfist 2014-09-04 10:22:11