<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                【android】初學安卓,簡單布局和activity切換 Email:chentravelling@163.com 為什么這個時候學安卓呢?當然是因為選修課啊......說好的機器學習暫時就擱淺了,所以就借了本安卓的書開始學習了。 ### 一、環境 Android Studio+JDK 1.8+win 7 ?64位 為什么選Android Studio呢?感覺很高大上,配置起來也很easy,只是配置模擬器的時候勞心費神了,而且耗內存太刁。言歸正傳吧! ### 二、布局 如果學過xml,有過寫網頁的經驗,那么寫安卓的界面布局就很easy了。只是,據說android有五大布局: (1)AbsoluteLayout:直接寫控件的x坐標和y坐標,很明顯這種方式不被推薦,因為Android系統的硬件分辨率不盡相同,使用這種布局方式無法實現自適應。 (2)RelativeLayout:這個方式就是設置控件相對于參照物的相對位置了,一般靈活吧。 (3)LinerLayout:很方便的布局,使用較多,就是將控件橫向或者縱向排列,嵌套起來用就更好了。 (4)FrameLayout:每個控件的左上方都與父容器左上方重疊 (5)GridLayout/TableLayout:經典案例就是用戶注冊。 TableLayout的特點:? Shrinkable : 該列的寬度可以進行收縮,以使表格能夠適應父容器的大小 Stretchable : 該列可以進行拉伸,以填滿表格中空閑的空間? Collapsed : 該列將會被隱藏? GridLayout的特點:? android:layout_row : ?固定顯示在第幾行。? android:layout_column : 固定顯示在第幾列,前面幾列沒控件的話就空著。? android:layout_rowSpan : 跨幾行? android:layout_columnSpan: ?跨幾列?? 本來想自己用LinerLayout和TableLayout兩種布局方式結合起來寫一個注冊界面的,唉,只可惜對布局這玩意不是特別來電,怎么弄都有點不好看,為了更快地去學習功能上的知識,于是就先把布局這塊放下了,用一個比較簡單的界面吧。取名:add_address.xml ~~~ <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:columnCount="5"> <TextView android:text="手機聯系人"/> <EditText android:hint="姓名" android:layout_columnSpan="4" android:layout_gravity="fill_horizontal" android:id="@+id/name"/> <TextView android:text="工作單位"/> <EditText android:layout_columnSpan="4" android:layout_gravity="fill_horizontal" android:id="@+id/workplace"/> <TextView android:text="手機號碼"/> <EditText android:layout_columnSpan="4" android:layout_gravity="fill_horizontal" android:id="@+id/phone"/> <TextView android:layout_marginTop="10dp" android:text="選擇性別"/> <RadioGroup android:layout_marginLeft="10dp" android:layout_columnSpan="4" android:layout_gravity="fill_horizontal" android:orientation="horizontal"> <RadioButton android:id="@+id/male" android:text="男" android:checked="true" android:layout_height="wrap_content" android:layout_width="wrap_content"/> <RadioButton android:id="@+id/female" android:text="女" android:layout_height="wrap_content" android:layout_width="wrap_content"/> </RadioGroup> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:text="增加" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/add"/> </LinearLayout> </GridLayout> ~~~ ![](https://box.kancloud.cn/2016-03-18_56eb6a33d72e0.jpg) ### 三、Activity 頁面跳轉是伴隨著不同的activity之間切換而跳轉的,不知道這說法有沒問題,先看看大概的代碼吧: 首先:寫AddAddressActivity.java ~~~ public class AddAddressActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_address); } } ~~~ 關鍵句子:就是setContentView();那么該activity啟動后就會打開一個新的界面,也就是我們設計的add_address.xml。接下來就是啟動這個activity了,很easy了,再另一個activity里啟動就可以了。 (1)一個activity啟動另一個activity 這個時候就需要activity之間通信的橋梁Intent:例如從MainActivity啟動AddAddressActivity,在MainActivity.java中寫 ~~~ Intent intent = new Intent(MainActivity.this, AddAddressActivity.class); startActivity(intent); ~~~ 如果有數據需要傳輸,那么就需要Bundle運載數據,Bundle在Java里相當于Map~ ~~~ Bundle bundle = new Bundle(); bundle.putString("name","嘿嘿"); bundle.putInt("age",22); ~~~ 在接受方,AddAddressActivity.java中: ~~~ Bundle bundle = this.getIntent().getExtras(); String name = bundle.getString("name"); int age = bundle.getInt("age"); ~~~ 暫時會這么一些了,接下來再看看SQLite存儲~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看