2012-08-28 187 views
1

目前我正在Android聊天屏幕應用程序,使用TabHost設置五個選項卡,然後我已經使用ListActivity在我的項目中創建ListView,但ListView顯示全屏,我想降低高度,因爲添加一個EditText底部的屏幕,請幫助我。如何在ListActivity(Android)中降低高度?

由於提前

我試過低於這個給你參考:

public class Texts extends ListActivity 
{ 
    String[] data={"How may i help you?", "Please help me", "Item 3","Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3"}; 

    Drawable[] usrimg=null; 
    String bgimg = "",_user="",_pass=""; 
    int odd_resID,even_resID; 

    public void onCreate(Bundle savedInstanceState) 
    { 
      super.onCreate(savedInstanceState); 
      System.out.println(" CHAT SCREEN "); 

      //finding the list view 
      ListView myList = getListView(); 
      myList.setAdapter(new MyCustomAdapter()); 
      myList.setCacheColorHint(0); 

//   setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListContent)); 
    } 
    class MyCustomAdapter extends BaseAdapter 
     { 

      /** 
      * returns the count of elements in the Array that is used to draw the text in rows 
      * @see android.widget.Adapter#getCount() 
      */ 
      @Override 
      public int getCount() 
      { 
       return data.length; // data is nothing but the message length 
      } 

      /** 
      * Get the data item associated with the specified position in the data set. 
      * (not Implemented at this point) 
      * @param position The position of the row that was clicked (0-n) 
      * @see android.widget.Adapter#getItem(int) 
      */ 
      @Override 
      public String getItem(int position) 
      { 
       // TODO Auto-generated method stub 
       return null; 
      } 

      /** 
      * Get the row id associated with the specified position in the list. 
      * (not implemented at this point) 
      * @param position The position of the row that was clicked (0-n) 
      * @see android.widget.Adapter#getItemId(int) 
      */ 
      @Override 
      public long getItemId(int position) 
      { 
       // TODO Auto-generated method stub 
       return position; 
      } 

      /** 
      * Returns the complete row that the System draws. 
      * It is called every time the System needs to draw a new row; 
      * You can control the appearance of each row inside this function. 
      * @param position The position of the row that was clicked (0-n) 
      * @param convertView The View object of the row that was last created. null if its the first row 
      * @param parent The ViewGroup object of the parent view 
      * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup) 
      */ 

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


       System.out.println("Enter here"); 


       LayoutInflater inflater = getLayoutInflater();//When you use a custom view in a ListView you must define the row layout. 
       //You create an xml where you place android widgets and then in the adapter's code 
       View row; 
       String even_color,odd_color; 

//    SharedPreferences prefList = getSharedPreferences("PrefsFile",MODE_PRIVATE); 
//    even_color = prefList.getString("even_bubble_color","pink"); 
//    odd_color = prefList.getString("odd_bubble_color","green"); 
//    
//    int even_color_id=getResources().getIdentifier(even_color,"drawable","com.teks.chilltwit"), 
//     odd_color_id=getResources().getIdentifier(odd_color,"drawable","com.teks.chilltwit"); 


       //ImageView even_view,odd_view; 


       System.out.println("Timeline: Position: "+position+", Length: "+data.length); 
//    if(position!=data.length-1){ 

       if(position%2==0) 
       { 
        row = inflater.inflate(R.layout.list_row_layout_even, parent, false); 
        TextView textLabel = (TextView) row.findViewById(R.id.text); 
        textLabel.setText(data[position]); 

       } 
       else 
       { 
        row = inflater.inflate(R.layout.list_row_layout_odd, parent, false); 
        TextView textLabel = (TextView) row.findViewById(R.id.text); 
        textLabel.setText(data[position]); 
       } 

       return (row); 
      } 
     } 

enter image description here

+1

請粘貼您的XML佈局 – Maragues

+0

感謝您的回覆,我沒有使用XML此屏幕的佈局,使用ListActivity來創建它。 – SampathKumar

+1

如果您使用的是ListActivity,您將無法在列表視圖下插入編輯文本。 ListActivity是一個列表視圖,就是這樣。你需要創建一個自定義XML文件才能夠做到這一點 – dymmeh

回答

2

嘗試使用片段來劃分您的屏幕,完成你想要的。

  • 頂部片段包含在ListView中的對話,就像你有。

  • 底部片段包含EditText上,「發送」按鈕,等

通過這種方式,用戶可以滾動到對話的任何部分能夠發送新郵件,而不必向下滾動。

Chat Fragment

+0

感謝您的幫助。 – SampathKumar

+0

我是Android開發新手,請你舉個簡單的例子。 – SampathKumar

+0

Android開發者指南解釋了[Fragments](http://developer.android.com/guide/components/fragments.html),你的SDK有示例程序。 – Sam

0

請嘗試將屏幕使用

權insted的使用PX的,DP ...等