我将图像和文本链接在一起以显示在片段中。一切都很好,除了每个项目下面出现的这条透明线。此行显示调用片段的活动的布局。我怎么能让这个fundraiser.xml占用所有的屏幕,无论我的列表中有多少项目以及如何在每个项目之后摆脱该行? 我上传了一张图片,以便更好地解释我的问题http://i.imgur.com/7F0EoHy.png
这是我的fundraiser.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="match_parent"
android:background="#000000" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:id="@+id/logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="5px"
android:layout_marginRight="20px"
android:src="@drawable/blai"
android:adjustViewBounds="true"
android:dividerHeight="-8dp"
android:background="#000000"
android:layout_weight="1">
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="380dp"
android:layout_height="12dp"
android:text="@+id/label"
android:textSize="30px"
android:layout_gravity="center_vertical"
android:background="#000000"
android:layout_weight="1">
</TextView>
</LinearLayout>
这是我的fundraiserfragmen文件
package com.github.devnied.emvnfccard.fragment;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import com.github.devnied.emvnfccard.adapter.MobileArrayAdapter;
public class FundraiserFragment extends ListFragment {
static final String[] values = new String[] {"Landsbjörg", "Blái Naglinn", "SÁÁ Álfurinn"};
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setListAdapter(new MobileArrayAdapter(getActivity(),values));
}
@Override
public void onListItemClick(ListView l, View v, int position, long ID) {
String value = (String) getListAdapter().getItem(position);
Toast.makeText(getActivity(), value, Toast.LENGTH_SHORT).show();
}
}
这是我的MobileArrayAdapter文件
package com.github.devnied.emvnfccard.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.github.devnied.emvnfccard.R;
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MobileArrayAdapter(Context context, String[] values) {
super(context, R.layout.fundraiser, R.id.label, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.fundraiser, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(values[position]);
// Change icon based on name
String s = values[position];
System.out.println(s);
if (s.equals("Landsbjörg")) {
imageView.setImageResource(R.drawable.landsbjorg);
} else if (s.equals("Blái Naglinn")) {
imageView.setImageResource(R.drawable.blai);
} else if (s.equals("SÁÁ Álfurinn")) {
imageView.setImageResource(R.drawable.saa_alfurinn);
} else {
imageView.setImageResource(R.drawable.ic_launcher);
}
return rowView;
}
}
答案 0 :(得分:3)
android:divider = "@null"
正如天网在评论中所说,或者如果你想以编程方式进行,你应该这样做:
getListView().setDivider(null);
方法中的onActivityCreated()
。
注意:在制作此
时没有看到其他答案答案 1 :(得分:1)
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
getListView().setDividerHeight(0);
setListAdapter(new MobileArrayAdapter(getActivity(),values));
}