簡體   English   中英

在android中刪除ListView頂部和底部的陰影?

[英]Remove shadow from top and bottom of ListView in android?

我創建了一個自定義listView,其行如下:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"  android:id="@+id/lay1" 
  android:layout_height="wrap_content" android:background="#ffffff">

  <TextView android:layout_width="fill_parent" android:textColor="#000000" android:id="@+id/text"
  android:layout_height="wrap_content" android:layout_toRightOf="@+id/check" 
  android:textSize="15dip" android:paddingBottom="5dip" android:paddingRight="10dip" android:paddingLeft="10dip"></TextView>

  <Button android:id="@+id/check"  android:layout_centerVertical="true"
          android:background="@drawable/uncheck" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:visibility="gone"></Button>

  <EditText android:layout_width="fill_parent" android:textColor="#000000" android:id="@+id/edit"
  android:layout_height="wrap_content"  android:background="@null" android:layout_below="@+id/text"
  android:textSize="15dip" android:paddingTop="5dip" android:paddingRight="10dip" android:paddingLeft="10dip"
  android:layout_toRightOf="@+id/check" android:paddingBottom="5dip" ></EditText>

</RelativeLayout>

我的主xml中使用的listview代碼是:

<ListView android:layout_width="450dip" android:background="#FFFFFF" android:layout_height="340dip" 
  android:layout_marginLeft="9dip" android:layout_marginTop="10dip"  android:id="@+id/mainlist1" 
  android:divider="@drawable/grayline" 
    android:cacheColorHint="#00000000" ></ListView>

使用的適配器如下:

public class Adapter extends BaseAdapter {


        ArrayList<Row> row;
        private Context context;


        public Adapter(Context context, ArrayList<SongRow> songrow) {

            this.context = context;
            this.row = row;

        }

        public int getCount() {

            return row.size();
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

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

            long sub_id = row.get(position).getSub_id();
            String sub_title = row.get(position).getSub_title();
            String sub_text = row.get(position).getSub_text();

            if (convertView == null) {
                LayoutInflater inflat = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflat.inflate(R.layout.mainrow, null);

            } else {
                LayoutInflater inflat1 = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflat1.inflate(R.layout.mainrow, null);
                            }
            final TextView name = (TextView) convertView.findViewById(R.id.text);
            final EditText et = (EditText) convertView.findViewById(R.id.edit);
            name.setText(sub_title);
            et.setText(sub_text);
            et.setFilters(new InputFilter[] { new InputFilter() {
                public CharSequence filter(CharSequence src, int start,
                        int end, Spanned dst, int dstart, int dend) {
                       InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                       mgr.hideSoftInputFromWindow(et.getWindowToken(),0);
                       et.setCursorVisible(false);
                       return dst.subSequence(dstart, dend);    

                }
            } });
            et.setOnFocusChangeListener(new OnFocusChangeListener() {

                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    // TODO Auto-generated method stub
                    if (hasFocus) {
                         InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                         mgr.hideSoftInputFromWindow(et.getWindowToken(),0);
                         et.setCursorVisible(false);
                    }
                }

            });
            et.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                     InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                     mgr.hideSoftInputFromWindow(et.getWindowToken(),0);
                     et.setCursorVisible(false);

                }
            });
            return convertView;
        }
    }

並通過代碼在主活動中調用適配器,如下所示:

Adapter s = new Adapter(MainActivity.this, row);
            mainlist.setAdapter(s);
            mainlist.setSelection(length-1);

我的編碼工作正常。 我的問題是,雖然顯示可滾動的listview是在listview的頂部和底部投下陰影,但我不想顯示它。 我該如何移除陰影?

提前致謝

我假設你在談論漸弱的邊緣。 要禁用它們:

android:fadingEdge="none"

要么

listView.setVerticalFadingEdgeEnabled(false);

UPDATE

正如Pim android:fadingEdge在評論中指出的那樣,不推薦使用android:fadingEdge ,從API級別14開始將被忽略。請使用:

android:fadingEdgeLength="0dp"

android:fadingEdgeLength對我android:fadingEdgeLength我用過android:overScrollMode="never"並且工作得很好android:overScrollMode="never"

android:overScrollMode="never"到ScrollView

這對我有用

android:fadeScrollbars="false"
android:fadingEdge="none"
android:fadingEdgeLength="0dp"
android:cacheColorHint="#00000000"
android:overScrollMode="never"

在XML ScrollView中使用它:

android:overScrollMode="never"

您可以設置為“always”,“never”或“ifContentScrolls”。

嘗試下面的代碼片段

listView.setVerticalFadingEdgeEnabled(false);

將其添加到XML中:

android:fadingEdge="none" or android:fadingEdgeLength="0dp"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM