如何在ListActivity(Android)中降低高度?

时间:2012-08-28 15:52:52

标签: android listview listactivity

目前我在Android聊天屏应用程序中工作,使用TabHost设置五个选项卡,然后我使用ListActivity在我的项目中创建ListView,但ListView全屏显示,我想降低高度,因为添加了EditText屏幕下方,请帮帮我。

先谢谢

我在下面尝试了这个,供您参考:

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

2 个答案:

答案 0 :(得分:2)

尝试使用片段分割屏幕并完成您想要的效果。

  • 顶部片段包含ListView中的对话,就像您一样。

  • 底部片段包含EditText,“发送”按钮等。

这样,用户可以滚动到会话的任何部分,并且能够发送新消息而无需向下滚动。

Chat Fragment

答案 1 :(得分:0)

尝试使用

划分屏幕

使用px,dp ...等的权重