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);
        }
     
  • 相关阅读:
    [读书笔记]捉虫日记
    花生壳建站全过程
    (step4.3.9)hdu 1584(蜘蛛牌——DFS)
    鼠标移到导航上面 当前的LI变色 处于当前的位置
    JavaScript学习笔记
    由Maximum Gap,对话桶排序,基数排序和统计排序
    安德鲁斯Launcher得到的装在手机的应用程序列表
    broadAnywhere:Broadcast组件权限绕过漏洞(Bug: 17356824)
    Ubuntu logomaker sh: 1: pngtopnm: not found 解决方案
    HDU 1598 find the most comfortable road (罗列+Kruskal) 并检查集合
  • 原文地址:https://www.cnblogs.com/maydow/p/4664576.html
Copyright © 2011-2022 走看看