他们为什么坚持彼此?

时间:2016-08-11 15:18:24

标签: android custom-lists

我正在尝试获取一个简单的自定义列表视图,并且因为元素相互粘连而看起来比以往任何时候都要糟糕。我已经创建了program_list.xml文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal|center_horizontal">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="1"
    android:id="@+id/TVIDC"
    android:layout_weight="1" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Name"
    android:id="@+id/TVNameC"
    android:layout_weight="1" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Date"
    android:id="@+id/TVDateC"
    android:layout_weight="1" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="0.00"
    android:id="@+id/TVAmountC"
    android:layout_weight="1" />
</LinearLayout>

这是CustomList文件:

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CustomList extends ArrayAdapter<String> {

private final Activity context;
private final Integer[] id;
private final String[] name;
private final Integer[] amount;
private final String[] date;


public CustomList(Activity context, Integer[] id, String[] name, Integer[] amount, String[] date) {
    super(context, R.layout.program_list, name);
    this.context = context;
    this.id = id;
    this.name = name;
    this.amount = amount;
    this.date = date;

}

@Override
public View getView(int position, View view, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View rowView = inflater.inflate(R.layout.program_list, null, true);
    TextView txtId = (TextView) rowView.findViewById(R.id.TVIDC);
    TextView txtName = (TextView) rowView.findViewById(R.id.TVNameC);
    TextView txtAmount = (TextView) rowView.findViewById(R.id.TVAmountC);
    TextView txtDate = (TextView) rowView.findViewById(R.id.TVDateC);


    txtId.setText(id[position]+"");
    txtName.setText(name[position]);
    txtAmount.setText(amount[position]+"");
    txtDate.setText(date[position]);


    return rowView;
}
}

快速找到解决方案,我很震惊,想在Play商店上传应用程序,并参考图片查看主要问题。提前感谢所有人,我必须写一些愚蠢的细节来删除红色框,不要想太多关于它,因为发布,我必须删除此框。这个愚蠢的盒子还没有消失。嘿堆栈溢出!它疯了。

这导致了问题:

Its what coming

但我想要这个:

Good one

2 个答案:

答案 0 :(得分:0)

将视图宽度更改为android:layout_width="0dp"。另外,我认为您不需要这一行android:gravity="fill_horizontal|center_horizontal"

答案 1 :(得分:0)

LinearLayout父级中应该缺少总和。

替换

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal|center_horizontal">

通过

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal|center_horizontal"
android:weightSum="4">