正如你看到的,高度通常設置當只有一個文本字符串,但所有的崩潰,當它包裹:如何使用自動換行自動更改佈局高度?
這裏是我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:focusable="true"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingStart="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingEnd="15dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/title"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</LinearLayout>
<CheckBox
android:id="@+id/checkbox"
android:theme="@style/checkBoxStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_marginTop="7dp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
/>
</LinearLayout>
這裏是我的適配器:
class AppsAdapter extends RecyclerView.Adapter<AppsAdapter.ViewHolder> {
private Activity activity;
private ArrayList<Item> items;
private int inflater;
private OnItemCheckListener onItemClick;
AppsAdapter (Activity activity, ArrayList<Item> items, int inflater, OnItemCheckListener onItemCheckListener) {
this.activity = activity;
this.items = items;
this.inflater = inflater;
this.onItemClick = onItemCheckListener;
}
static class ViewHolder extends RecyclerView.ViewHolder {
private ImageView icon;
private TextView title, descr, version;
private CheckBox checkbox;
private ViewHolder (View view) {
super (view);
icon = (ImageView) view.findViewById (R.id.icon);
title = (TextView) view.findViewById (R.id.title);
descr = (TextView) view.findViewById (R.id.descr);
version = (TextView) view.findViewById (R.id.version);
checkbox = (CheckBox) view.findViewById (R.id.checkbox);
}
}
@Override
public ViewHolder onCreateViewHolder (ViewGroup parent, int viewType) {
return new ViewHolder (LayoutInflater.from (parent.getContext()).inflate (inflater, parent, false));
}
@Override
public void onBindViewHolder (final ViewHolder holder, int position) {
Item item = items.get (position);
if (holder.icon != null)
holder.icon.setImageDrawable (item.icon);
holder.title.setText (item.getItem (0));
holder.descr.setText (item.getItem (1));
// Other actions...
}
}
那麼,真的這麼做嗎?我不希望使用非標準Android設置的活動,因爲我要支持奇巧(4.4),但其默認的主題是可怕的(
或者,也許這將是與TableLayout和解決方案等等?
在此先感謝
遺憾的是它不工作。 PaddingBottom不是一個解決方案( – Acuna
我認爲佈局設計是完美的,問題是您的自定義視圖添加在viewGroup中,您能告訴我代碼在哪裏膨脹視圖嗎? –
您是指XML還是programmaticaly?我編輯過 – Acuna