從零開始學android(Tablelayout表格版面配置.十五.)

來源:互聯網
上載者:User

從零開始學android(Tablelayout表格版面配置.十五.)

TableLayout就是將手機的螢幕分為一行行的形式進行資料的顯示,並且一行可以多個控制項

並且可以設定控制項的對齊,和是否為可收縮行

下面通過一行圖和一個簡單的例子來看看Tablelayout布局的使用


…………………………………………………………毫無美感的分割線…………………………………………………………

單獨使用xml檔案進行配置

//第三行允許行合并                                                                                                   
運行


從上面的運行效果大家可以很清楚地看到,第一行第二行分別顯示了兩個組件,第三行顯示了一個組件,並設定了劇中對齊的效果。<喎?http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+oa2hraGtoa2hraGtoa2hraGtoa2hraGtoa2hraGtoa2hraGtoa2hraGtoa26wc7ew8C40LXEt9a47s/foa2hraGtoa2hraGtoa2hraGtoa2hraGtoa2hraGtoa2hraGtoa2hraGtoa08YnI+CjwvcD4KPHA+tq/MrLK8vta1xLe9yr3Ktc/WoaM8L3A+CjxwPjxwcmUgY2xhc3M9"brush:java;">package com.example.tablelayout;import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.view.ViewGroup;import android.widget.Button;import android.widget.EditText;import android.widget.TableLayout;import android.widget.TableRow;import android.widget.TextView;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// setContentView(R.layout.tablelayout);TableLayout layout = new TableLayout(this);//建立Tablelayout對象//設定Tablelayout的對齊TableLayout.LayoutParams tableTLayoutParams = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);TableRow tableRow1=new TableRow(this);//建立第一行TableRow tableRow2=new TableRow(this);//建立第二行TableRow tableRow3=new TableRow(this);//建立第三行TextView textView1=new TextView(this);//建立Textview對象textView1.setText("使用者名稱");EditText editText1=new EditText(this);//建立EditText對象tableRow1.addView(textView1);//TextView設定到第一行tableRow1.addView(editText1);//EditText設定到第一行TextView textView2=new TextView(this);//建立Textview對象textView2.setText("密 碼");EditText editText2=new EditText(this);//建立EditText對象tableRow2.addView(textView2);//TextView設定到第一行tableRow2.addView(editText2);//EditText設定到第二行Button button=new Button(this);button.setText("登入系統");tableRow3.setGravity(Gravity.CENTER);//設定第三行九中對齊tableRow3.addView(button);layout.addView(tableRow1);//將第一行資料添加到布局當中layout.addView(tableRow2);//將第二行資料添加到布局當中layout.addView(tableRow3);//將第三行資料添加到布局當中super.setContentView(layout,tableTLayoutParams);}}

動態布局同樣可以實現xml布局實現的效果


下節預報:相對布局RelativeLayout


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.