Skip to content

Commit

Permalink
fragment优化
Browse files Browse the repository at this point in the history
  • Loading branch information
AranAndroid009 committed Aug 19, 2021
1 parent 7eed14f commit 3db932c
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 68 deletions.
24 changes: 0 additions & 24 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
package com.aranandroid.customview.ui

import android.annotation.SuppressLint
import android.app.Activity
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.widget.RadioButton
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import com.aranandroid.customview.R
import com.aranandroid.customview.squareview.SquareTextView
import com.aranandroid.customview.ui.square.AFragment
import com.aranandroid.customview.ui.square.BFragment
import com.aranandroid.customview.ui.square.*
import kotlinx.android.synthetic.main.activity_square_moreview.*
import kotlinx.android.synthetic.main.activity_square_textview.*
import kotlinx.android.synthetic.main.item_main.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

class SquareMoreActivity : FragmentActivity() {
@SuppressLint("WrongViewCast")
Expand All @@ -30,10 +18,13 @@ class SquareMoreActivity : FragmentActivity() {
square_text_image.imageView.setOnClickListener{v ->
Toast.makeText(this ,"click",Toast.LENGTH_SHORT).show()
}
fragment_top.fragments = linkedMapOf(Pair(R.id.f, AFragment()),Pair(R.id.h, BFragment()))
fragment_top.changeItme={group, checkedId ->
fragment_bottom.fragments = linkedMapOf(Pair(R.id.a, AFragment()),Pair(R.id.b, BFragment()),Pair(R.id.c, CFragment()),Pair(R.id.d, DFragment()))
fragment_bottom.changeItme={group, checkedId ->
Log.e("TAG", "onCreate: "+checkedId )
}

fragment_top.fragments = linkedMapOf(Pair(R.id.f, FFragment()),Pair(R.id.h, HFragment()))

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.aranandroid.customview.ui.square

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.aranandroid.customview.R

class CFragment() : Fragment(R.layout.fragment_c) {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.aranandroid.customview.ui.square

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.aranandroid.customview.R

class DFragment() : Fragment(R.layout.fragment_d) {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.aranandroid.customview.ui.square

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.aranandroid.customview.R

class FFragment() : Fragment(R.layout.fragment_f) {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.aranandroid.customview.ui.square

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.aranandroid.customview.R

class HFragment() : Fragment(R.layout.fragment_h) {


}
94 changes: 74 additions & 20 deletions app/src/main/res/layout/activity_square_moreview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,98 @@
>
</com.aranandroid.customview.squareview.SquareTextImage>

<com.aranandroid.customview.fragment.FragmentBottom

<com.aranandroid.customview.fragment.FragmentTop
android:id="@+id/fragment_top"
android:layout_width="match_parent"
android:layout_height="500dp">
<com.aranandroid.customview.squareview.SquareLinearLayout
android:layout_height="@dimen/dp_40"
app:corner="5dp"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:padding="3dp"
app:background_color="@color/red"
android:layout_width="match_parent">
<com.aranandroid.customview.squareview.SquareRadioButton
<com.aranandroid.customview.squareview.SquareRadioButton
android:layout_margin="2dp"
android:id="@+id/f"
android:layout_height="30dp"
android:layout_width="0dp"
android:layout_weight="1"
app:selected_corner="5dp"
android:checked="true"
app:selected_background_color="@color/colorAccent"
android:gravity="center"
android:text="F"
tools:ignore="MissingConstraints" />

<com.aranandroid.customview.squareview.SquareRadioButton
android:layout_margin="2dp"
android:id="@+id/h"
android:layout_height="30dp"
android:layout_width="0dp"
android:layout_weight="1"
app:selected_corner="5dp"
app:selected_background_color="@color/colorAccent"
android:gravity="center"
android:text="H"
tools:ignore="MissingConstraints" />
</com.aranandroid.customview.fragment.FragmentTop>


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="ddd"
></TextView>
<com.aranandroid.customview.fragment.FragmentBottom
android:id="@+id/fragment_bottom"
android:layout_width="match_parent"
android:layout_marginTop="150dp"
android:layout_height="500dp">
<!-- <com.aranandroid.customview.squareview.SquareLinearLayout-->
<!-- android:layout_height="@dimen/dp_40"-->
<!-- app:corner="5dp"-->
<!-- android:layout_marginLeft="@dimen/dp_10"-->
<!-- android:layout_marginRight="@dimen/dp_10"-->
<!-- android:padding="3dp"-->
<!-- app:background_color="@color/red"-->
<!-- android:layout_width="match_parent">-->
<RadioButton
android:layout_margin="2dp"
android:id="@+id/f"
android:id="@+id/a"
android:layout_height="30dp"
android:layout_width="0dp"
android:layout_weight="1"
app:selected_corner="5dp"
android:checked="true"
app:selected_background_color="@color/colorAccent"
android:gravity="center"
android:text="F"
android:text="A"
tools:ignore="MissingConstraints" />

<com.aranandroid.customview.squareview.SquareRadioButton
<RadioButton
android:layout_margin="2dp"
android:id="@+id/h"
android:id="@+id/b"
android:layout_height="30dp"
android:layout_width="0dp"
android:layout_weight="1"
app:selected_corner="5dp"
app:selected_background_color="@color/colorAccent"
android:gravity="center"
android:text="H"
android:text="B"
tools:ignore="MissingConstraints" />
</com.aranandroid.customview.squareview.SquareLinearLayout>
<RadioButton
android:layout_margin="2dp"
android:id="@+id/c"
android:layout_height="30dp"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="C"
tools:ignore="MissingConstraints" />
<RadioButton
android:layout_margin="2dp"
android:id="@+id/d"
android:layout_height="30dp"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="D"
tools:ignore="MissingConstraints" />
<!-- </com.aranandroid.customview.squareview.SquareLinearLayout>-->
</com.aranandroid.customview.fragment.FragmentBottom>


</LinearLayout>
</ScrollView>
</com.aranandroid.customview.title.TitleLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_c.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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:ignore="MissingDefaultResource">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="62sp"
android:text="C" />

</LinearLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_d.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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:ignore="MissingDefaultResource">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="62sp"
android:text="D" />

</LinearLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_f.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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:ignore="MissingDefaultResource">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="62sp"
android:text="F" />

</LinearLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_h.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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:ignore="MissingDefaultResource">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="62sp"
android:text="H" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,17 @@ class FragmentBottom(context: Context?, attrs: AttributeSet?) : LinearLayout(con
super.dispatchDraw(canvas)
// addChildrenForAccessibility()
val children = children
for (child in children) {
if (child.id != R.id.fragment_top) {
(child.parent as ViewGroup).removeView(child)
radio.addView(child)
fragments?.keys?.let {
for (id in it) {
for (child in children) {
if (child.id == id) {
(child.parent as ViewGroup).removeView(child)
radio.addView(child)
}
}
}
}

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aranandroid.customview.fragment

import android.app.Activity
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
Expand Down Expand Up @@ -82,10 +81,14 @@ class FragmentTop(context: Context?, attrs: AttributeSet?) : LinearLayout(contex
super.dispatchDraw(canvas)
// addChildrenForAccessibility()
val children = children
for (child in children) {
if(child.id != R.id.fragment_top){
(child.parent as ViewGroup).removeView(child)
radio.addView(child)
fragments?.keys?.let {
for (id in it) {
for (child in children) {
if (child.id == id) {
(child.parent as ViewGroup).removeView(child)
radio.addView(child)
}
}
}
}
}
Expand Down

0 comments on commit 3db932c

Please sign in to comment.