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);
        }
     
  • 相关阅读:
    sublime text 3 package control
    互联网协议入门
    java String.split()函数的用法分析
    Java 路径
    matplotlib安装问题
    简单工程使用sbt公共库(sbt-assembly)
    通俗理解LDA主题模型
    基于协同过滤,NMF和Baseline的推荐算法
    贝叶斯集锦套装
    [转]
  • 原文地址:https://www.cnblogs.com/maydow/p/4664576.html
Copyright © 2011-2022 走看看