parent
5f5f8bb45c
commit
890af8cfcd
@ -0,0 +1,156 @@ |
||||
package com.gyf.csams |
||||
|
||||
import androidx.compose.foundation.Canvas |
||||
import androidx.compose.foundation.background |
||||
import androidx.compose.foundation.layout.* |
||||
import androidx.compose.material.Text |
||||
import androidx.compose.runtime.Composable |
||||
import androidx.compose.ui.Alignment |
||||
import androidx.compose.ui.Modifier |
||||
import androidx.compose.ui.draw.rotate |
||||
import androidx.compose.ui.graphics.Color |
||||
import androidx.compose.ui.graphics.drawscope.rotate |
||||
import androidx.compose.ui.text.SpanStyle |
||||
import androidx.compose.ui.text.buildAnnotatedString |
||||
import androidx.compose.ui.text.withStyle |
||||
import androidx.compose.ui.tooling.preview.Preview |
||||
import androidx.compose.ui.unit.dp |
||||
import androidx.compose.ui.unit.sp |
||||
|
||||
|
||||
@Composable |
||||
fun BoxSetSize(degrees:Float=0F,content: @Composable BoxScope.() -> Unit){ |
||||
Box(modifier = Modifier |
||||
.height(300.dp) |
||||
.fillMaxWidth() |
||||
.background(Color.Gray) |
||||
.rotate(degrees = degrees),contentAlignment = Alignment.Center){ |
||||
Canvas(modifier = Modifier.size(200.dp)) { |
||||
rotate(45f){ |
||||
drawRect(color = Color.Cyan) |
||||
} |
||||
} |
||||
content() |
||||
} |
||||
} |
||||
|
||||
@Composable |
||||
fun BoxFillSize(degrees:Float=0F, content: @Composable BoxScope.() -> Unit){ |
||||
Box(modifier = Modifier |
||||
.fillMaxSize() |
||||
.background(Color.LightGray) |
||||
.rotate(degrees = degrees),contentAlignment = Alignment.Center){ |
||||
Canvas(modifier = Modifier.size(100.dp)) { |
||||
rotate(80f){ |
||||
drawRect(color = Color.Cyan) |
||||
} |
||||
} |
||||
content() |
||||
} |
||||
} |
||||
|
||||
@Preview |
||||
@Composable |
||||
fun TestPreview(){ |
||||
Column(modifier = Modifier.fillMaxSize()){ |
||||
BoxSetSize { |
||||
Text(buildAnnotatedString { |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("前置子布局固定尺寸") |
||||
} |
||||
}) |
||||
} |
||||
|
||||
BoxFillSize { |
||||
Text(buildAnnotatedString { |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("后置子布局使用") |
||||
} |
||||
withStyle(style = SpanStyle(color= Color.Red,fontSize = 30.sp)){ |
||||
append("fillMaxSize修饰符") |
||||
} |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("填充父项允许的所有可用空间") |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Preview |
||||
@Composable |
||||
fun TestPreview2(){ |
||||
Column(modifier = Modifier.fillMaxSize()){ |
||||
Text(buildAnnotatedString { |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("如果使用示例1方法是") |
||||
} |
||||
withStyle(style = SpanStyle(color= Color.Red,fontSize = 30.sp)){ |
||||
append("无法实现前置子布局填充父项所有可用空间,后置子布局固定尺寸") |
||||
} |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("因为前置布局已经填充父项允许的所有可用空间,后置子布局没有剩余空间可用") |
||||
} |
||||
|
||||
}) |
||||
|
||||
BoxFillSize { |
||||
Text(buildAnnotatedString { |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("前置子布局填充父项允许的所有可用空间") |
||||
} |
||||
}) |
||||
} |
||||
|
||||
BoxSetSize { |
||||
Text(buildAnnotatedString { |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("后置子布局固定尺寸") |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Preview |
||||
@Composable |
||||
fun TestPreview3(){ |
||||
Column(modifier = Modifier |
||||
.fillMaxSize()) { |
||||
Text(buildAnnotatedString { |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("折衷方案是通过父项旋转180°实现,子项分别旋转180°复位可") |
||||
} |
||||
withStyle(style = SpanStyle(color= Color.Red,fontSize = 30.sp)){ |
||||
append("实现前置子布局填充父项所有可用空间,后置子布局固定尺寸") |
||||
} |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append(",除了旋转,应该有更好的实现方式?") |
||||
} |
||||
}) |
||||
Column(modifier = Modifier.rotate(180F)){ |
||||
BoxSetSize(degrees = 180F) { |
||||
Text(buildAnnotatedString { |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("前置子布局固定尺寸,通过旋转和后置子布局对调位置") |
||||
} |
||||
}) |
||||
} |
||||
BoxFillSize(degrees = 180F) { |
||||
Text(buildAnnotatedString { |
||||
|
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("后置子布局使用") |
||||
} |
||||
withStyle(style = SpanStyle(color= Color.Red,fontSize = 30.sp)){ |
||||
append("fillMaxSize修饰符") |
||||
} |
||||
withStyle(style = SpanStyle(fontSize = 30.sp)){ |
||||
append("填充父项允许的所有可用空间,通过旋转和前置子布局对调位置") |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M644.8,581.57l160.64,187.46a64,64 0,0 1,-48.6 105.64L267.16,874.67a64,64 0,0 1,-48.6 -105.64l160.66,-187.43a253.81,253.81 0,0 0,61.21 26.94l-173.27,202.13h489.69l-173.27,-202.13a254.61,254.61 0,0 0,61.23 -26.97zM512,149.33c117.82,0 213.33,95.51 213.33,213.33S629.82,576 512,576s-213.33,-95.51 -213.33,-213.33S394.18,149.33 512,149.33zM512,213.33A149.33,149.33 0,1 0,512 512a149.33,149.33 0,0 0,0 -298.67z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M644.8,581.57l160.64,187.46A64,64 0,0 1,756.84 874.67H267.16a64,64 0,0 1,-48.6 -105.64l160.66,-187.43A254.81,254.81 0,0 0,512 618.67c48.64,0 94.08,-13.55 132.8,-37.1zM512,149.33c117.82,0 213.33,95.51 213.33,213.33s-95.51,213.33 -213.33,213.33 -213.33,-95.51 -213.33,-213.33S394.18,149.33 512,149.33z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M490.67,533.33v256a64,64 0,0 1,-64 64h-192a64,64 0,0 1,-64 -64v-192a64,64 0,0 1,64 -64h256zM789.33,533.33a64,64 0,0 1,64 64v192a64,64 0,0 1,-64 64h-192a64,64 0,0 1,-64 -64L533.33,533.33h256zM426.67,597.33h-192v192h192v-192zM789.33,597.33h-192v192h192v-192zM426.67,170.67a64,64 0,0 1,64 64v256L234.67,490.67a64,64 0,0 1,-64 -64v-192a64,64 0,0 1,64 -64h192zM693.33,170.67a160,160 0,1 1,0 320,160 160,0 0,1 0,-320zM426.67,234.67h-192v192h192v-192zM693.33,234.67a96,96 0,1 0,0 192,96 96,0 0,0 0,-192z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M490.67,533.33v256a64,64 0,0 1,-64 64h-192a64,64 0,0 1,-64 -64v-192a64,64 0,0 1,64 -64h256zM789.33,533.33a64,64 0,0 1,64 64v192a64,64 0,0 1,-64 64h-192a64,64 0,0 1,-64 -64L533.33,533.33h256zM426.67,170.67a64,64 0,0 1,64 64v256L234.67,490.67a64,64 0,0 1,-64 -64v-192a64,64 0,0 1,64 -64h192zM693.33,170.67a160,160 0,1 1,0 320,160 160,0 0,1 0,-320z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M810.67,213.33a64,64 0,0 1,64 64L874.67,704a64,64 0,0 1,-64 64L478.34,768l-146.65,96.11a21.33,21.33 0,0 1,-33.02 -17.86L298.67,768h-85.33a64,64 0,0 1,-64 -64L149.33,277.33a64,64 0,0 1,64 -64h597.33zM810.67,277.33L213.33,277.33L213.33,704h149.33v63.3L459.24,704h351.42L810.67,277.33zM539.31,490.67v64h-176.64v-64h176.64zM661.33,362.67v64L362.67,426.67v-64h298.67z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M556.59,159.36l288.49,183.91A64,64 0,0 1,874.67 397.25v392.75a64,64 0,0 1,-64 64H555.46l0.02,-196.99H490.67v196.99H234.67a64,64 0,0 1,-64 -64v-398.29a64,64 0,0 1,30.27 -54.4l287.53,-178.35a64,64 0,0 1,68.14 0.43zM810.67,790.02V397.23L522.2,213.33 234.67,391.68v398.34h192v-197.01h192.81v196.99H810.67z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M556.59,159.36l288.49,183.91A64,64 0,0 1,874.67 397.25v392.75a64,64 0,0 1,-64 64l-224,-0.02V597.33H448v256.64l-213.33,0.04a64,64 0,0 1,-64 -64V391.68a64,64 0,0 1,30.27 -54.4l287.53,-178.35a64,64 0,0 1,68.14 0.43z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M938.67,256c0,-46.93 -38.4,-85.33 -85.33,-85.33L170.67,170.67c-46.93,0 -85.33,38.4 -85.33,85.33v512c0,46.93 38.4,85.33 85.33,85.33h682.67c46.93,0 85.33,-38.4 85.33,-85.33L938.67,256zM853.33,256l-341.33,212.91L170.67,256h682.67zM853.33,768L170.67,768L170.67,341.33l341.33,213.33 341.33,-213.33v426.67z"/> |
||||
</vector> |
Loading…
Reference in new issue