android ActivityGroup 的使用

來源:互聯網
上載者:User

代碼部分:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <LinearLayout         android:gravity="center_horizontal"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        >        <TextView             android:id="@+id/cust_title"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textColor="@android:color/white"            android:textSize="18sp"            />    </LinearLayout>    <!-- 中間動態載入view -->     <ScrollView          android:id="@+id/containerBody"         android:layout_width="fill_parent"         android:layout_height="300dip"         >              </ScrollView>          <LinearLayout          android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_gravity="bottom"         android:orientation="horizontal"         >         <!-- 功能模組1 -->         <ImageView              android:id="@+id/btnModule1"             android:src="@android:drawable/ic_dialog_dialer"             android:layout_marginLeft="7dip"             android:layout_marginTop="3dip"             android:layout_marginBottom="3dip"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />                  <!-- 功能模組2 -->         <ImageView              android:id="@+id/btnModule2"             android:src="@android:drawable/ic_dialog_info"             android:layout_marginLeft="7dip"             android:layout_marginTop="3dip"             android:layout_marginBottom="3dip"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />                  <!-- 功能模組按鈕3 -->         <ImageView              android:id="@+id/btnModule3"             android:src="@android:drawable/ic_dialog_alert"             android:layout_marginLeft="7dip"             android:layout_marginTop="3dip"             android:layout_marginBottom="3dip"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />     </LinearLayout></LinearLayout>
package com.yek;import android.app.ActivityGroup;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageView;import android.widget.ScrollView;import android.widget.TextView;public class LearnActivity extends ActivityGroup implements OnClickListener{        private TextView title;    private ScrollView contain;    private ImageView btnOne;    private ImageView btnTwo;    private ImageView btnThree;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_group_layout);        initView();        setListener();    }        private void initView(){        title = (TextView)findViewById(R.id.cust_title);        contain = (ScrollView)findViewById(R.id.containerBody);        btnOne = (ImageView)findViewById(R.id.btnModule1);        btnTwo = (ImageView)findViewById(R.id.btnModule2);        btnThree = (ImageView)findViewById(R.id.btnModule3);    }        private void setListener(){        btnOne.setOnClickListener(this);        btnTwo.setOnClickListener(this);        btnThree.setOnClickListener(this);            }    @Override    public void onClick(View v) {        switch (v.getId()) {        case R.id.btnModule1:            btnOneListener(ModuleView1.class);            break;        case R.id.btnModule2:            btnOneListener(ModuleView2.class);            break;        case R.id.btnModule3:            btnOneListener(ModuleView3.class);            break;        }    }        private void btnOneListener(Class clazz){        contain.removeAllViews();        View view = getLocalActivityManager().startActivity("Module1", new Intent(this,clazz).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();        contain.addView(view);    }    }
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:text="@string/hello"         android:id="@+id/content"        />    </LinearLayout>
package com.yek;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ModuleBaseActivity extends Activity {    private TextView content;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        content = (TextView)findViewById(R.id.content);            }        /**     * 設定內容     * @param str     */    public void setContentText(String str){        content.setText(str);    }        /**     * 設定背景色     * @param colorId     */    public void setBackground(int colorId){        content.setBackgroundColor(colorId);    }}
package com.yek;import android.graphics.Color;import android.os.Bundle;public class ModuleView1 extends ModuleBaseActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setBackground(Color.RED);        setContentText("模組一");    }}
package com.yek;import android.graphics.Color;import android.os.Bundle;public class ModuleView2 extends ModuleBaseActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setBackground(Color.GREEN);        setContentText("模組二");    }}
package com.yek;import android.graphics.Color;import android.os.Bundle;public class ModuleView3 extends ModuleBaseActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setBackground(Color.BLUE);        setContentText("模組三");    }}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.