zoukankan      html  css  js  c++  java
  • 自定义BaseActivity

    之前在网上看到一个一种方法:

    public class BaseActivity extends Activity {  
      
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            requestWindowFeature(Window.FEATURE_NO_TITLE);  
            setContentView(R.layout.base);  
        }  
      
        public void baseSetContentView(int layoutResId) {  
            LinearLayout llContent = (LinearLayout) findViewById(R.id.content);  
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
            View v = inflater.inflate(layoutResId, null);  
            llContent.addView(v);  
        }  
      
    }  

    经过测试,用这种方法加进去的view都是wrap_content的

    需要改成inflate.inflate(layoutResId,llContent);

        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            setTheme(R.style.MyTheme);//注意这一句的位置
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            setContentView(R.layout.activity_basechart);
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
            
        }
        public void baseSetContentView(int layoutResId) {  
            LinearLayout llContent = (LinearLayout) findViewById(R.id.baseContent);  
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
            inflater.inflate(layoutResId, llContent);  
        } 
    activity_basechart.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        android:background="#FFFFFF">
         <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_margin="2dp"
                android:orientation="vertical"
                android:layout_weight="1"
                android:padding="2dp"
                android:background="@drawable/border">
               <com.github.mikephil.charting.charts.LineChart
                android:id="@+id/chart"
                android:background="@color/tp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
           </RelativeLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:id="@+id/baseContent"
            android:layout_weight="1">
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="vertical"
            android:layout_weight="1">
            <android.support.v4.view.ViewPager
                android:id="@+id/baseVallery"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </android.support.v4.view.ViewPager>
        </LinearLayout>
    </LinearLayout>

    新建Activity继承自上面的BaseActivity

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            baseSetContentView(R.layout.activity_monitor);
        }
     
  • 相关阅读:
    在 MVC 控制器中使用 构造函数时行依赖注入 (IoC)
    跟我学 NHibernate (三)
    跟我学 NHibernate (二)
    跟我学 NHibernate (一)
    使用PetaPoco ORM 框架分页查询
    ASP.NET MVC 中使用 AjaxFileUpload 插件时,上传图片后不能显示(预览)
    在 mvc 中使用下拉列表
    String.Join() 方法 的用法
    动态为页面添加CSS样式文件引用
    禁止页面内按F5键进行刷新(扩展知识:禁止复制信息内容)
  • 原文地址:https://www.cnblogs.com/maydow/p/4664576.html
Copyright © 2011-2022 走看看