zoukankan      html  css  js  c++  java
  • 布局

    六个布局

    https://www.cnblogs.com/buchizaodian/category/887038.html

    一、复用布局

     <include layout="@layout/activity_main2">
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical">
    
        <include layout="@layout/activity_main2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="aa"/>
    </LinearLayout>

    activity_main2

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="HELLO" />
    </LinearLayout>

    PS:

        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
            //隐藏系统自动bar
            supportActionBar?.hide()
            }

    二、创建自定义控件

    复用只是使他的布局重复使用,触发的事件效果还要自己在当前activity重写。

    如果想让事件也可以复用的话,可以自定义控件 

    com.rockcheck.konlintest.test.Lay 引入布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical">
    
      <com.rockcheck.konlintest.test.Lay
          android:layout_width="match_parent"
          android:layout_height="wrap_content"/>
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="aa"/>
    </LinearLayout>

    公共控件

    Lay.kt

    class Lay(context:Context,attrs:AttributeSet):LinearLayout(context, attrs) {
        init {
            LayoutInflater.from(context).inflate(R.layout.activity_main2,this)
            button.setOnClickListener{
                Toast.makeText(context,"hi",Toast.LENGTH_SHORT).show()
            }
        }
    }

    三、

    androidx.constraintlayout.widget.ConstraintLayout
  • 相关阅读:
    266. Palindrome Permutation
    265. Paint House II
    264. Ugly Number II
    263. Ugly Number
    261. Graph Valid Tree
    260. Single Number III
    259. 3Sum Smaller
    pthon 批量压缩当前目录,子目录下图片
    不小心打开了N多的压缩文件窗口,一句命令就搞定!
    # Writing your-first Django-app-part 4-simple-form
  • 原文地址:https://www.cnblogs.com/buchizaodian/p/12717865.html
Copyright © 2011-2022 走看看