简体   繁体   English

编辑listView,页边空白

[英]Edit listView , margin top

I have a list view that looks like this 我有一个看起来像这样的列表视图

列表显示

and that's its code .. 这就是它的代码..

package com.a.c;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class calender extends ListActivity {
   /** Called when the activity is first created. */
   @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, calendr));
    getListView().setTextFilterEnabled(true);

}

static final String[] calendr = new String[]{
    "MONT Blanc",
    "Gucci",
    "Parker",
    "Sailor",
    "Porsche Design",
    "Rotring",
    "Sheaffer",
    "Waterman"
};}

i want to modify it to add this layout ,, and shift the listview downward little bit 我想修改它以添加此布局,并向下移动listview

the image looks like a picture frame that's why i want to move the list view .. 图像看起来像相框,这就是为什么我要移动列表视图的原因..

Layout code at .XML file .XML文件中的布局代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/relativeLayout1"
 android:layout_width="600px"
 android:layout_height="1024px"
 xmlns:android="http://schemas.android.com/apk/res/android">


<ImageView android:id="@+id/layout" 
            android:src="@drawable/layout" 
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent"
           android:layout_alignParentBottom="true" 
           android:layout_alignParentLeft="true" 
           android:layout_alignParentRight="true" 
          android:layout_alignParentTop="true"></ImageView>

       </RelativeLayout>

Hi You can use this code and achieve your target: 嗨,您可以使用此代码并实现您的目标:

   main.xml
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/layout"
        android:src="@drawable/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></ImageView>
    <ListView
        android:layout_width="match_parent"
        android:id="@+id/listViewScore"
        android:cacheColorHint="#00000000"
        android:layout_height="match_parent"
        android:layout_weight="1.00"
        android:divider="#C0C0C0"
        android:layout_below="@+id/layout"
        android:dividerHeight="2dip" />

</RelativeLayout>


  listviewtext.xml

<?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="match_parent">
    <TextView
        android:text="Name"
        android:id="@+id/textViewName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"></TextView>


</LinearLayout>


    public class TestProjeectActivity extends Activity {

        private ListView listViewScore = null;
        private ListViewAdapter listViewAdapter = null;
        private String[] usernameArr = null;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            listViewScore=(ListView)findViewById(R.id.listViewScore);

            usernameArr = new String[]{"Alan","Bob","Carl","Doaniel","Evan","Fred","Gram","Ian","Jordan"};

            listViewAdapter = new ListViewAdapter();
            listViewScore.setAdapter(listViewAdapter);
        }

        class ListViewAdapter extends BaseAdapter{

            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                if(usernameArr==null){
                    return 0;
                }

                return usernameArr.length;
            }

            @Override
            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return usernameArr[position];
            }

            @Override
            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
            }

            @Override
            public View getView(int position, View view, ViewGroup parent) {
                // TODO Auto-generated method stub
                View rowView=view;

                if(rowView==null){
                    LayoutInflater layoutinflate =LayoutInflater.from(TestProjeectActivity.this);
                    rowView=layoutinflate.inflate(R.layout.listviewtext, parent, false);
                }

                TextView textViewName=(TextView)rowView.findViewById(R.id.textViewName);

                textViewName.setText(usernameArr[position]);

                return rowView;
            }

        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM