2013-07-17 51 views
1

這裏是我到目前爲止的代碼。我應該改變什麼,使它看起來像下面的ASCII藝術?編程方式:在頂部的EditText和按鈕的Android的ListView在底部

private RelativeLayout mMainLayout; 
private LinearLayout mButtonLayout; 
private ListView mListView; 
private EditText mMessageInput; 
private Button mSendButton; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mMainLayout = new RelativeLayout(this); 
    mMainLayout.setLayoutParams(new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, 
    LinearLayout.LayoutParams.MATCH_PARENT)); 
    setContentView(mMainLayout); 
    mMainLayout.setGravity(Gravity.BOTTOM); 

    mListView = new ListView(this); 
    mMainLayout.addView(mListView, 0); 

    mButtonLayout = new LinearLayout(this); 
    mButtonLayout.setLayoutParams(new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, 
    LinearLayout.LayoutParams.WRAP_CONTENT, 2f)); 
    mMessageInput = new EditText(this); 
    mMessageInput.setMinimumHeight(200); 
    mButtonLayout.addView(mMessageInput, 0); 

    mSendButton = new Button(this); 
    mSendButton.setText(R.string.send); 
    mSendButton.setOnClickListener(this); 
    mButtonLayout.addView(mSendButton, 1); 
    mMainLayout.addView(mButtonLayout, 1); 
} 


------------------------- 
|ListView    | 
|      | 
|      | 
|      | 
|      | 
|      | 
|      | 
|      | 
|      | 
------------------------- 
| EditText  |Button | 
------------------------- 

回答

3
private LinearLayout mMainLayout; 
private LinearLayout mButtonLayout; 
private ListView mListView; 
private EditText mMessageInput; 
private Button mSendButton; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
mMainLayout = new LinearLayout(this); 
mMainLayout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 
LinearLayout.LayoutParams.MATCH_PARENT)); 
mMainLayout.setOrientation(LinearLayout.VERTICAL); 
setContentView(mMainLayout); 
mMainLayout.setGravity(Gravity.BOTTOM); 

mButtonLayout = new LinearLayout(this); 
mButtonLayout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 
LinearLayout.LayoutParams.WRAP_CONTENT, 2f)); 
mMessageInput = new EditText(this); 
mMessageInput.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 
LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); 
mButtonLayout.addView(mMessageInput, 0); 

mSendButton = new Button(this); 
mSendButton.setText(R.string.send); 
mSendButton.setOnClickListener(this); 
mSendButton.setLayoutParams(new LinearLayout.LayoutParams(
     LinearLayout.LayoutParams.MATCH_PARENT, 
LinearLayout.LayoutParams.WRAP_CONTENT, 3f)); 
mSendButton.setMinHeight(300); 
mButtonLayout.addView(mSendButton, 1); 
mMainLayout.addView(mButtonLayout, 1); 

mListView = new ListView(this); 
mListView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 
LinearLayout.LayoutParams.MATCH_PARENT, 1f)); 
mMainLayout.addView(mListView, 0); 

你應該從底部佈局到頂部像上面的代碼。所以首先在佈局中添加底部的兩個按鈕,然後添加列表視圖。 我希望它對你有幫助。

1

這裏是解決方案:

private LinearLayout mMainLayout; 
private LinearLayout mButtonLayout; 
private ListView mListView; 
private EditText mMessageInput; 
private Button mSendButton; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mMainLayout = new LinearLayout(this); 
    mMainLayout.setLayoutParams(new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, 
     LinearLayout.LayoutParams.MATCH_PARENT)); 
    mMainLayout.setOrientation(LinearLayout.VERTICAL); 
    setContentView(mMainLayout); 
    mMainLayout.setGravity(Gravity.BOTTOM); 

    mListView = new ListView(this); 
    mListView.setLayoutParams(new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, 
    LinearLayout.LayoutParams.MATCH_PARENT, 1f)); 
    mMainLayout.addView(mListView, 0); 

    mButtonLayout = new LinearLayout(this); 
    mButtonLayout.setLayoutParams(new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, 
    LinearLayout.LayoutParams.WRAP_CONTENT, 2f)); 
    mMessageInput = new EditText(this); 
    mMessageInput.setLayoutParams(new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, 
    LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); 
    mButtonLayout.addView(mMessageInput, 0); 

    mSendButton = new Button(this); 
    mSendButton.setText(R.string.send); 
    mSendButton.setOnClickListener(this); 
    mSendButton.setLayoutParams(new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.MATCH_PARENT, 
    LinearLayout.LayoutParams.WRAP_CONTENT, 3f)); 
    mSendButton.setMinHeight(300); 
    mButtonLayout.addView(mSendButton, 1); 
    mMainLayout.addView(mButtonLayout, 1); 
相關問題