Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更改ListView中项目的高度_Java_Android_Android Layout_Listview_Android Ui - Fatal编程技术网

Java 更改ListView中项目的高度

Java 更改ListView中项目的高度,java,android,android-layout,listview,android-ui,Java,Android,Android Layout,Listview,Android Ui,我正在设计一个应用程序来浏览各种源代码。 要浏览这些行,我选择将它们放入ListView。 我已经构建了自定义适配器来处理自定义项布局。所有的高度都设置为包装内容,但android似乎并不关心这一点,两行之间有一个令人讨厌的空白 如果我以编程方式手动将layoutParams中的高度值设置为固定值,即30,则问题已得到解决,但我发现此解决方案很难看,希望了解此不需要的间距的原因 以下是我的布局: <LinearLayout xmlns:android="http://schemas.and

我正在设计一个应用程序来浏览各种源代码。 要浏览这些行,我选择将它们放入ListView。 我已经构建了自定义适配器来处理自定义项布局。所有的高度都设置为包装内容,但android似乎并不关心这一点,两行之间有一个令人讨厌的空白

如果我以编程方式手动将layoutParams中的高度值设置为固定值,即30,则问题已得到解决,但我发现此解决方案很难看,希望了解此不需要的间距的原因

以下是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sourcerow"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:padding="0dip"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:weightSum="1.0" >

    <TextView
        android:id="@+id/linenumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.06"
        android:minWidth="30dip"
        android:padding="0dip"
        android:text="@string/line" />

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.94"
        android:padding="0dip" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="0dip" >

            <TextView
                android:id="@+id/indent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="0dip"
                android:text=""
                android:textAlignment="viewStart" />

            <TextView
                android:id="@+id/thecode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="0dip"
                android:text="@string/code"
                android:textAlignment="viewStart" />
        </LinearLayout>
    </HorizontalScrollView>

</LinearLayout>

你正在删除代码行中的换行符吗?不,我认为它们是由fromHtml自动删除的。这个workedfromHTML实际上会将它们转换为。
@Override
public View getView(int pos, View v, ViewGroup vg) {
    codeLine entry = code.getCode().get(pos);
    if (null == v) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.source_row, null);
    }
    if(pos%2==0) v.setBackgroundResource(R.drawable.selector_1);
    else v.setBackgroundResource(R.drawable.selector_2);
    LinearLayout row = (LinearLayout) v.findViewById(R.id.sourcerow);
    TextView linenumber = (TextView) v.findViewById(R.id.linenumber);
    TextView linecode = (TextView) v.findViewById(R.id.thecode);
    TextView indent = (TextView) v.findViewById(R.id.indent);
    linenumber.setText(Integer.toString(pos+1));
    indent.setText(indent(entry.getDepth()));
    linecode.setText(Html.fromHtml(entry.getCode()));
    AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
    row.setLayoutParams(params);
    row.setPadding(0, 0, 0, 0);
    return v;
}