ANDROID-删除listview标头图像的多余空间 [英] ANDROID - Remove extra space of listview header image

查看:51
本文介绍了ANDROID-删除listview标头图像的多余空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有标题图像的列表视图,图像的顶部和底部有多余的空间.我要从中删除空间,

I have a listview with a header image , there is extra space top and bottom of the image . I want to remove the space from it ,

如果有人知道,请帮忙,我的布局是LinierLayout?我的xml文件已关闭

My layout is LinierLayout if anyone knows please help ? my xml files is down

这是列表项xml的代码

this is the code for list items xml

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

    <TextView
        android:text="TextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray"
        android:textColor="@android:color/white"
        android:id="@+id/tvHeader"
        android:visibility="gone" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvHeader"
        android:orientation="horizontal"
        android:paddingLeft="10dp">

        <ImageView
            android:id="@+id/imageView"
            android:layout_gravity="center"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="0dp"
            android:layout_marginTop="10dp"
            android:paddingBottom="0dp"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="10dp"/>
        <!--  img  -->


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="30dp"
            android:layout_marginRight="5dp">


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                >

                <TextView
                    android:id="@+id/fname"
                    android:text="Name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"

                    android:textColor="#000"
                    android:textSize="12sp"
                    android:textStyle="bold"

                    android:layout_weight="1"/>

                <TextView
                    android:text="TextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/lname"
                    android:textColor="#000"
                    android:textSize="12sp"
                    android:textStyle="bold"
                    android:layout_marginLeft="10dp"/>

            </LinearLayout>

            <TextView
                android:text="TextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/organizationname"
                android:textSize="10sp"
                android:paddingTop="10px" />

            <TextView
                android:text="yyyyyyyyyyyyyyyyy"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/idposition"
                android:textSize="10sp"
                android:layout_below="@+id/fname"
                android:layout_alignLeft="@+id/fname"
                android:layout_alignStart="@+id/fname" />

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

这是适配器文件

import android.content.*;
import android.graphics.*;
import android.os.*;
import android.util.Log;
import android.view.*;
import android.widget.*;

import com.parse.*;
import com.squareup.picasso.*;

import org.w3c.dom.Text;

import java.io.*;
import java.net.*;
import java.util.*;

public class IndividualsAdaptor extends ArrayAdapter {
    private static final int TYPE_SECTION_HEADER = 0;
    private static final int TYPE_LIST_ITEM = 1;
    protected Context mContext;
    ArrayList<Integer> mListHeader = new ArrayList<>();
    // Code for Custom Filter.
    protected List mBackupList = new ArrayList();
    public IndividualsAdaptor(Context context, List status) {
        super(context, R.layout.t3, status);
        mContext = context;
        // Code for Custom Filter.
        mBackupList.addAll(status);
    }
    @Override
    public int getViewTypeCount() { return 2; }
    @Override
    public int getItemViewType(int position)
    {
        if (mListHeader.contains(position)){
            return TYPE_SECTION_HEADER;
        } else {
            return TYPE_LIST_ITEM;
        }
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.t3, null);
            holder = new ViewHolder();
            holder.tvHeader = (TextView) convertView.findViewById(R.id.tvHeader);
            holder.usernameHomepage = (TextView) convertView.findViewById(R.id.fname);
            holder.statusHomepage = (TextView) convertView.findViewById(R.id.lname);
            holder.pposition = (TextView) convertView.findViewById(R.id.idposition);
            holder.orgName = (TextView) convertView.findViewById(R.id.organizationname);
            holder.logo = (ImageView) convertView.findViewById(R.id.imageView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ParseObject statusObject = (ParseObject) getItem(position);
        // title
        String username = statusObject.getString("firstname");
        holder.usernameHomepage.setText(username);
        // content
        String status = statusObject.getString("lastname");
        holder.statusHomepage.setText(status);
        // Header
        if(getItemViewType(position) == TYPE_SECTION_HEADER){
            holder.tvHeader.setVisibility(View.VISIBLE);
            holder.tvHeader.setText(String.valueOf(status.charAt(0)));
        }else{
            holder.tvHeader.setVisibility(View.GONE);
        }
        // content
        String positions = statusObject.getString("position");
        holder.pposition.setText(positions);
        // content
        String org = statusObject.getString("organizationName");
        holder.orgName.setText(org);
        // logo
        URL url = null;
        Bitmap bmp = null;
        try {
            url = new URL("file location" + statusObject.getString("image"));
            bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        } catch (MalformedURLException e) {
        }catch (IOException e) {
        }
        holder.logo.setImageBitmap(bmp);
        Picasso.with(mContext)
                .load(String.valueOf(url))
                .transform(new Rounded( ))
                .into(((ImageView) convertView
                        .findViewById(R.id.imageView)));
        return convertView;
    }
    public static class ViewHolder {
        TextView tvHeader;
        TextView usernameHomepage;
        TextView statusHomepage;
        TextView orgName;
        TextView pposition;
        ImageView logo;
    }
    @Override
    public Filter getFilter() {return new Filter(){
        @Override
        protected FilterResults performFiltering(CharSequence charSequence) {
            String queryString = charSequence.toString().toLowerCase();
            List<ParseObject> filteredList = new ArrayList<>();
            ParseObject tmpItem;
            String tmpUsername, tmpStatus, tmpPositions, tmpOrg;
            for(int i=0; i<mBackupList.size(); i++){
                tmpItem = (ParseObject) mBackupList.get(i);
                tmpUsername = tmpItem.getString("firstname").toLowerCase();
                tmpStatus = tmpItem.getString("lastname").toLowerCase();
                tmpPositions = tmpItem.getString("position").toLowerCase();
                tmpOrg = tmpItem.getString("organizationName").toLowerCase();
                // The matching condition
                if(tmpUsername.contains(queryString)||tmpStatus.contains(queryString)||
                        tmpPositions.contains(queryString)||tmpOrg.contains(queryString)){
                    filteredList.add(tmpItem);
                }
            }
            FilterResults filterResults = new FilterResults();
            filterResults.count = filteredList.size();
            filterResults.values = filteredList;
            return filterResults;
    }
    @Override
    protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
        clear();
        addAll((List<ParseObject>) filterResults.values);
    }
    };}
    public void updateBackupList(List newList){
        mBackupList.clear();
        mBackupList.addAll(newList);
    }
    public void updateHeaderList(ArrayList<HashMap> newHeaderList){
        for(int i=0; i<newHeaderList.size(); i++){
            mListHeader.add(Integer.parseInt((String)newHeaderList.get(i).get("position")));
        }
        Log.d("Test", mListHeader.toString());
    }
}

java文件

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

   <RelativeLayout
        android:id="@id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="110dp"
    />


    <TextView android:id="@+id/tvEmpty"
              android:layout_width="match_parent"
              android:layout_height="60dp"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true"
              android:background="#083266"/>

   <SearchView
        android:id="@+id/ser1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:queryHint="Search.."
        android:background="@color/FBC_RED"
        android:layout_below="@id/tvEmpty"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="0dp">
    </SearchView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_below="@+id/ser1">

        <ListView
            android:id="@id/android:list"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.89" />

        <ListView
            android:id="@+id/listIndex"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:scrollbars="none"
            android:layout_weight="0.08">
        </ListView>


    </LinearLayout>
</LinearLayout>

推荐答案

这应该有效:

ListView listView = getListView(); 
ImageView mListHeader = new ImageView(getContext()); 
mListHeader.setImageResource(R.drawable.individuals_img); 
mListHeader.setScaleType(ImageView.ScaleType.FIT_XY); 
mListHeader.setLayoutParams(new AbsListView.LayoutParams(1400,974)); 
mListHeader.requestLayout(); 
listView.addHeaderView(mListHeader); 

这篇关于ANDROID-删除listview标头图像的多余空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆