zoukankan      html  css  js  c++  java
  • 大二下学期每日总结

    今日学习了布局服务的一些基本内容:

    获取LayoutInflater实例  LayoutInflater inflater=new LayoutInflater.from(this);

    加载布局文件inflate(int resoure,ViewGroup,boolean ToRoot) 第一个参数为布局资源对应的id,后两个与嵌套父布局与外部容器有关,一般天null和false。

    动态添加XML布局:

    获取LayoutInflater对象 LayoutInflater inflater=new LayoutInflater.from(this);

    加载布局 inflater.nflate(布局文件id,null,false).findViewById(...);

    通过 RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams()设置相关属性并设置位置lp.addRule();

    加载布局 addView(ly,lp)将lp用ly替换。

    public class MainActivity2 extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main2);
            final LayoutInflater inflater=LayoutInflater.from(this);
            final RelativeLayout rl=(RelativeLayout)findViewById(R.id.relativeLayout);
        }
        public void onClick(View view){
            final LayoutInflater inflater=LayoutInflater.from(this);
            final RelativeLayout rl=(RelativeLayout)findViewById(R.id.relativeLayout);
            RelativeLayout ly=(RelativeLayout) inflater.inflate(R.layout.inflate,null,false).findViewById(R.id.inflate);
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            lp.addRule(RelativeLayout.CENTER_IN_PARENT);
            rl.addView(ly,lp);
        }
    }
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity2"
        android:background="@drawable/dahe"
        android:id="@+id/relativeLayout">
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_marginEnd="34dp"
            android:layout_marginRight="34dp"
            android:layout_marginBottom="500dp"
            android:onClick="onClick"
            android:text=" ( ゜- ゜)つロ 乾杯~①"
            android:textSize="26dp"></Button>
    
    </RelativeLayout>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/inflate"
        android:gravity="center"
        android:orientation="vertical">
    
        <Button
            android:id="@+id/button1"
            android:layout_width="306dp"
            android:layout_height="63dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_marginEnd="48dp"
            android:layout_marginRight="48dp"
            android:layout_marginBottom="205dp"
            android:text=" ( ゜- ゜)つロ 乾杯~①"
            android:textSize="26dp"></Button>
    
        <ImageView
            android:layout_width="323dp"
            android:layout_height="482dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_marginEnd="36dp"
            android:layout_marginRight="36dp"
            android:layout_marginBottom="155dp"
            android:src="@drawable/qidan"></ImageView>
    
    </RelativeLayout>
  • 相关阅读:
    Mvc Tree的简单应用
    nodeJs的学习之路(1)
    AngularJs基础学习指南(1)
    前端工程化讲解
    前端性能优化--为什么DOM操作慢?
    This package contains perl-5.16.3, java8, nifi-1.1.2 on ubuntu:14.04
    This package contains sshd, pcal, mysql-client on Ubuntu14:04
    This package contains mysql-server on ubuntu:14.04
    NIFI-创建一个FlowFile并利用PutFile保存到到指定目录
    NIFI如何利用eclipse开发自己的Processor(下)
  • 原文地址:https://www.cnblogs.com/fengchuiguobanxia/p/14477398.html
Copyright © 2011-2022 走看看