gpt4 book ai didi

android - 在 android 中使用布局适配器时,在线性布局中重复显示标题图像

转载 作者:行者123 更新时间:2023-11-29 17:55:40 25 4
gpt4 key购买 nike

我正在开发一个安卓应用程序。我需要在我的页面上显示搜索结果。我页面中的线性布局由我用作标题的图像组成。布局适配器和 View 支架用于显示详细信息。问题是当我得到结果时,每个搜索结果都会显示标题图像。我只需要显示一次图像标题,我该怎么做。这是我的布局和代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/main_layout1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageheader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"

android:src="@drawable/logo"
android:adjustViewBounds="true"/>
<!-- -->
</LinearLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/ScrollViewSearch" >

<LinearLayout
android:id="@+id/main_layout2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip">

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >

<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="15dp" />

</LinearLayout>
<TextView
android:id="@+id/textViewUser1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

/>
<TextView
android:id="@+id/textViewUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/textViewUser1"
android:text="Maradona"
android:paddingLeft="10dp"/>

<!-- Artist Name -->
<TextView
android:id="@+id/textViewUserid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Maradoncssdsdsda"
android:textColor="#343434"
android:textSize="12dip"
android:layout_toRightOf="@+id/textViewUser1"
android:layout_below="@+id/textViewUser"
android:paddingLeft="10dp"/>


</RelativeLayout>
<AbsoluteLayout
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="25dp"
android:layout_height="19dp"
android:layout_marginBottom="5dip"/>

<TextView
android:id="@+id/textView4"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="3dp"
android:paddingRight="10dp"
android:text=" Send Message"
android:clickable="true"
android:textColor="#028dca"
android:textSize="12dip" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="25dp"
android:layout_height="19dp"
android:layout_marginBottom="5dip"

android:layout_x="120dp"
android:layout_y="3dp" />

<TextView
android:id="@+id/textView4"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_x="150dp"
android:layout_y="3dp"
android:paddingRight="10dp"
android:text="Full Profile "
android:textColor="#028dca"
android:textSize="12dip"/>

</AbsoluteLayout>

</LinearLayout>
</ScrollView>
</LinearLayout>

类文件是

public class LazyAdapter extends BaseAdapter {
private ListActivity activity;
private LayoutInflater layoutInflater;
private ArrayList<String> names;
private FbUser[] folks;
private int folksNumber = 0;


public LazyAdapter(ListActivity activity, ArrayList<String> names) {
super();

this.activity = activity;
this.names = names;
this.folks = new FbUser[this.names.size()];
layoutInflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

new FetchDataTask(this, 0).execute(new Void[]{});
}



public View getView(int position, View convertView, ViewGroup parent) {
FbUser cachedUser = folks[position]; // trying to get a user from cache

View item = convertView;
ViewHolder viewHolder;

/**
* If item has not been created yet, we inflate it and pass its personal
* ViewHolder as a tag parameter. Otherwise we just get an existing
* ViewHolder.
*/
if (item == null) {
//LinearLayout aa=(LinearLayout)item.findViewById(R.id.main_layout);
item = layoutInflater.inflate(R.layout.quicksearchresult, null);
viewHolder = new ViewHolder();

viewHolder.textView = (TextView) item.findViewById(R.id.textViewUser);
viewHolder.textView1 = (TextView) item.findViewById(R.id.textViewUserid);
viewHolder.textView2 = (TextView) item.findViewById(R.id.textViewUser1);
viewHolder.spinner = (ProgressBar) item.findViewById(R.id.progressBar);
item.setTag(viewHolder);





} else {
viewHolder = (ViewHolder) item.getTag();
}

/**
* If the current user has been fetched we put cached data to the view.
* Otherwise we clear the view.
*/
if (cachedUser != null) {

viewHolder.textView.setText(cachedUser.getName());
viewHolder.textView1.setText(cachedUser.getUserid());
viewHolder.spinner.setVisibility(View.GONE);
viewHolder.textView2.setCompoundDrawablesWithIntrinsicBounds(
new BitmapDrawable(activity.getResources(), cachedUser
.getBitmap()), null, null, null);


} else {
viewHolder.textView.setText("");
viewHolder.spinner.setVisibility(View.VISIBLE);
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(
null, null, null, null);
viewHolder.textView1.setCompoundDrawablesWithIntrinsicBounds(
null, null, null, null);
}

return item;
}


@Override
public int getCount() {
return names.size();
}

@Override
public Object getItem(int position) {
return names.get(position);
}


@Override
public long getItemId(int position) {
return 0;
}


public void cacheUser(FbUser user) {
folks[folksNumber] = user;
folksNumber++;
notifyDataSetChanged(); //reload ListView
}


private static class ViewHolder {
public TextView textView,textView1,textView2;
public ImageView image1;
public LinearLayout lay;
public ProgressBar spinner;
}

最佳答案

似乎对于列表中的每个项目,您都在膨胀整个 xml 文件。您想要将该 xml 文件拆分为两个不同的文件,一个包含标题和一个 ListView (activity_layout.xml),然后另一个将是每个单独行的布局 (row_layout.xml)。然后在您的适配器类中,对于每个项目,使用 row_layout.xml 填充单独的行。

关于android - 在 android 中使用布局适配器时,在线性布局中重复显示标题图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19650902/

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