Infragment.java主要代码
```java
public class InfFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
private SwipeRefreshLayout swipeRefreshLayou;
ListView lv_Inf;
String[] arrayFriends=new String[]{"小红","小花","小美"};
int[] head=new int[]{R.mipmap.xh,R.mipmap.xhua,R.mipmap.xm};
String[] logo=new String[]{"数学第一题怎么做呀?","这周末有空吗?","记得晚上出来吃饭哦!"};
@Override
protected int getLayoutId() {
return R.layout.fragment_inf;
}
@Override
protected void initView() {
swipeRefreshLayou=find(R.id.inf_swiperefresh);
swipeRefreshLayou.setOnRefreshListener(this);
lv_Inf= find(R.id.list);
setData();//给列表添加数据
}
private void setData() {
SimpleAdapter simpleAdapter=new SimpleAdapter(
getActivity(),
getData(),
R.layout.layout_inf_item,
new String[]{"name","head","logo"},
new int[]{R.id.iv_item_name,R.id.lv_item_head,R.id.lv_item_logo}
);
lv_Inf.setAdapter(simpleAdapter);
}
private List<Map<String,Object>> getData() {
List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
for (int i=0;i<head.length;i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("name",arrayFriends[i]);
map.put("head",head[i]);
map.put("logo",logo[i]);
list.add(map);
}
return list;
}
@Override
public void onRefresh() {
swipeRefreshLayou.setRefreshing(false);
}
}
fragment_inf.xml布局代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/inf_swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/ll_inf"
android:background="@color/btnLogin"
>
<ImageView
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_width="40sp"
android:layout_height="40sp"
android:src="@mipmap/tx"
/>
<TextView
android:textSize="20dp"
android:layout_marginTop="25dp"
android:layout_marginLeft="120dp"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="消息"
/>
<ImageView
android:layout_marginTop="25dp"
android:layout_width="match_parent"
android:layout_height="30sp"
android:src="@drawable/ic_inf_add_24"
/>
</LinearLayout>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="88dp"
app:layout_constraintTop_toBottomOf="@id/ll_inf">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_search_24" />
<EditText
android:id="@+id/inf_edt_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="18dp"
android:background="@color/white"
android:cursorVisible="false"
android:focusable="auto"
android:gravity="center"
android:hint="搜索"
android:minHeight="30dp"
android:textSize="16sp" />
</androidx.appcompat.widget.Toolbar>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="560dp"
app:layout_constraintBottom_toBottomOf="@+id/inf_swiperefresh"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
layout_inf_item.xml布局代码
```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:orientation="horizontal">
<ImageView
android:src="@mipmap/qq333"
android:id="@+id/iv_item_name"
android:layout_width="60dp"
android:layout_height="60dp"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lv_item_head"
android:textSize="25sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lv_item_logo"
android:textSize="20sp"
/>
</LinearLayout>
</LinearLayout>
我的代码运行截图如下
我想要的是下面这种效果
求帮助啊 我觉得应该是嵌套的问题,因为我是自己网上学习的fragment,这个listview是跟着别人做的,我就想把两个结合起来,结果就成这样了