不能鍵入任何字符我有一個list.xml的LayoutParams無法正常工作,在EditText上
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.phongponix.trackingbodybuilding.MainActivity$PlaceholderFragment"
android:orientation="vertical"
>
<ListView android:id="@+id/lvExerciseList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="50dp"
></ListView>
</LinearLayout>
我list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="20dp"
android:id="@+id/containerTest">
<LinearLayout
android:id="@+id/first_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imgExcercisePhoto"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:id="@+id/tvExerciseName"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="aaa" />
</LinearLayout>
<RelativeLayout android:id="@+id/rlRecordContainer"
android:layout_width="150dp"
android:layout_height="match_parent"
android:orientation="horizontal">
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvExcerciseRecords"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/first_panel"
android:clipToPadding="false"
android:scrollbars="horizontal"></android.support.v7.widget.RecyclerView>
</LinearLayout>
我用適配器我的列表,下面:
if (convertView == null) {
view = inflater.inflate(R.layout.list_item, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) view.findViewById(R.id.tvExerciseName);
view.setTag(viewHolder);
LinearLayout container = (LinearLayout)view.findViewById(R.id.first_panel);
LinearLayout.LayoutParams layoutParamsWeight = new LinearLayout.LayoutParams(convertDpToPixel(activity, 30), convertDpToPixel(activity, 20));
layoutParamsWeight.setMargins(0, 0, convertDpToPixel(activity, 5), convertDpToPixel(activity, 5));
EditText etWeight = new EditText(activity);
etWeight.setWidth(convertDpToPixel(activity, 30));
etWeight.setHeight(convertDpToPixel(activity, 20));
//etWeight.setLayoutParams(layoutParamsWeight);
etWeight.setBackgroundColor(ContextCompat.getColor(activity, R.color.colorEditTextBox));
etWeight.setInputType(InputType.TYPE_CLASS_NUMBER);
etWeight.setFocusableInTouchMode(true);
//etWeight.setId(currentWeightID);
container.addView(etWeight);
RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.rlRecordContainer);
renderRecordItemHead(activity, relativeLayout);
renderRecordItem(activity, relativeLayout, currentWeightID);
recyclerView = (RecyclerView) view.findViewById(R.id.rvExcerciseRecords);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(trackingPlanHorizontalAdapter);
}
如在下圖中,如果我註釋掉(不使用)的LayoutParams,我可以輸入和顯示的字符在我的EditText。如果我爲EditText使用LayoutParams,則無法輸入。鍵盤出現在單擊EditText時,然後失去焦點,因此每次觸摸鍵盤時都不顯示任何內容。
_do不認真對待我的話_你的問題沒有任何意義,如果你不應用layoutParams ViewGroup應用一個默認的參數,這是'Wrap_CONTENT'如果你(phongtran )apply layoutparam你給它確定的大小'新的LinearLayout.LayoutParams(convertDpToPixel(activity,30)'這就是爲什麼他們的行爲就像那樣,我是對嗎? – Elltz
是鍵盤可見的,當你點擊edittext應用layoutparams? –