2012-01-04 101 views
0

我有一個看起來像這樣編輯的ListView,距頂部

listview

,這就是它的代碼列表視圖..

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" 
};} 

我想修改它來添加此佈局,,並將列表視圖向下移動一點點

圖像看起來像一個圖片框架,這就是爲什麼我想要移動列表視圖..

在.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> 
+0

這不是clear.What你想幹什麼?你正在添加圖像,你沒有做任何事情的屏幕底部。 – DuyguK 2012-01-04 16:29:14

回答

0

嗨,您可以使用此代碼,實現您的目標:

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; 
      } 

     } 
    } 
+0

它沒有工作,我onliy想要定義相對佈局,圖像視圖在Java和邊緣頂部的列表向下移動它 – user1009889 2012-01-05 06:56:15

+0

@ user1009889我編輯了xml的代碼,並根據您的要求相對所有東西 – Maverick 2012-01-05 14:14:44

+0

我試過ur修改後的代碼,但R.layout.listviewtext和(R.id.textViewName)沒有在.xml中定義,我在哪裏放置它們的佈局? – user1009889 2012-01-10 19:59:13