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);
        }
     
  • 相关阅读:
    POJ 3419 Difference Is Beautiful (DP + 二分 + rmq)
    CodeForces 755C PolandBall and Forest (并查集)
    CodeForces 754D Fedor and coupons (优先队列)
    CodeForces 753C Interactive Bulls and Cows (Hard)
    CodeForces 754C Vladik and chat (DP+暴力)
    HDU 1996 汉诺塔VI (排列组合)
    HDU 1995 汉诺塔V (水题)
    HDU 2077 汉诺塔IV (递推)
    HDU 2064 汉诺塔III (递推)
    How Javascript works (Javascript工作原理) (二) 引擎,运行时,如何在 V8 引擎中书写最优代码的 5 条小技巧
  • 原文地址:https://www.cnblogs.com/maydow/p/4664576.html
Copyright © 2011-2022 走看看