gpt4 book ai didi

Android GridView 从适配器添加 header ?

转载 作者:太空狗 更新时间:2023-10-29 13:55:04 26 4
gpt4 key购买 nike

我设法更新了适配器的标题 View 。 listview, headerView (from listview), gridview 在一个屏幕内。问题是因为listview和headerView显示的是同一个item,我想隐藏list view以免出现。我该怎么做?

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View rootView = inflater.inflate(R.layout.fragment_home, container, false);

final Context gridContext = rootView.getContext();
gridView = (GridViewWithHeaderAndFooter) rootView.findViewById(R.id.grid);

this.inflaterGeneral = inflater;
headerView = inflaterGeneral.inflate(R.layout.cell_fragment_home_header_list, null);
listViewHeader = (ListView) headerView.findViewById(R.id.listViewHeader);
rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

return rootView;
}

我的图像适配器

class ImageAdapterHeader extends BaseAdapter {
private Context context;
private final String[] mobileValues;

private TextView t;

public ImageAdapterHeader(Context context, String[] mobileValues) {
this.context = context;
this.mobileValues = mobileValues;
}

public View getView(int position, View convertView, ViewGroup parent) {

LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

//View v = convertView;
ViewHolder holder;

final Item i = itemVideo.get(position);
if (i != null) {
final VideoDetail ei = (VideoDetail) i;

//begin
if (convertView == null) {
convertView = inflater.inflate(R.layout.cell_fragment_home_header, null);
holder = new ViewHolder();
holder.imgThumbnail = (ImageView) convertView.findViewById(R.id.imgThumbnail);
holder.txtDuration = (Button) convertView.findViewById(R.id.txtDuration);
holder.txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);
holder.txtName = (TextView) convertView.findViewById(R.id.txtName);
holder.txtView = (TextView) convertView.findViewById(R.id.txtView);
holder.txtComment = (TextView) convertView.findViewById(R.id.txtComment);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.txtDuration.setText(ei.getDuration());
holder.txtTitle.setText(ei.getTitle());
holder.txtView.setText(ei.getViewCount());
holder.txtComment.setText(ei.getLikeCount());

Picasso.with(this.context)
.load(ei.getDetailPreview().replace(" ", "%20"))
.error(R.drawable.ic_launcher).into(holder.imgThumbnail);

holder.imgThumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().runOnUiThread(new Runnable() {
public void run() {

Intent intent = new Intent(getContext(), VideoPlayerActivity.class);
intent.putExtra("videoId", ei.getVideoId());
intent.putExtra("title", ei.getTitle());
intent.putExtra("artistName", ei.getArtistName());
intent.putExtra("view", ei.getViewCount());
intent.putExtra("like", ei.getLikeCount());
startActivity(intent);

}
});

}
});
} else {
System.out.println("Item Null");
}
//end
return convertView;
}

fragment 首页

<?xml version="1.0" encoding="utf-8"?>
<in.srain.cube.views.GridViewWithHeaderAndFooter
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="2"
android:scrollbarStyle="outsideOverlay"
android:verticalScrollbarPosition="right"
android:scrollbars="vertical"
android:descendantFocusability="beforeDescendants"
android:background="#d9d8d8" >
</in.srain.cube.views.GridViewWithHeaderAndFooter>

单元格 fragment 主页头列表

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ListView
android:id="@+id/listViewHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#d9d8d8"
android:scrollingCache="false" />

</LinearLayout>

单元格 fragment 首页标题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dp">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >

<ImageView
android:id="@+id/imgThumbnail"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/jen4d" />

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >

<ImageView
android:id="@+id/imgPlay"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="200dp"
android:background="@drawable/button_play"
android:scaleType="fitXY"
android:src="@drawable/button_play" />
</RelativeLayout>

<Button
android:id="@+id/txtDuration"
android:layout_width="50dp"
android:layout_height="20dp"
android:layout_alignBottom="@+id/xtName"
android:layout_alignLeft="@+id/imgThumbnail"
android:layout_alignRight="@+id/imgThumbnail"
android:layout_alignTop="@+id/play"
android:layout_gravity="bottom|right"
android:layout_marginBottom="65dp"
android:layout_marginRight="20dp"
android:background="@drawable/round"
android:gravity="center_horizontal|center_vertical"
android:text="3:20"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@drawable/transparan"
android:orientation="vertical"
android:layout_alignBottom="@+id/xtName"
android:layout_alignLeft="@+id/imgThumbnail"
android:layout_alignRight="@+id/imgThumbnail"
android:layout_alignTop="@+id/txtDuration"
android:layout_gravity="right|bottom">

<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:text="Klepek - Klepek Versi Dance &apos;Dangduters&apos;"
android:textColor="#ff8a65" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="0.3"
android:orientation="horizontal" >

<TextView
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:text="Janeta Janet"
android:textColor="#FFFFFF" />

</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingBottom="25dp" >

<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_remove_red_eye_white_24dp"
android:paddingLeft="10dp"
android:layout_marginLeft="10dp" />

<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="10000"
android:textColor="#FFFFFF" />

<ImageView
android:layout_width="19dp"
android:layout_height="19dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"
android:src="@drawable/ic_chat_white_24dp" />

<TextView
android:id="@+id/txtComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="10000"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>

最佳答案

尝试使用 [HeaderGridView][1],它是 GridView 的子类。希望对您有所帮助。

关于Android GridView 从适配器添加 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40543482/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com