это только начало

This commit is contained in:
VictoriaPresnyakova 2023-10-01 21:55:07 +04:00
parent 5b0505c4c5
commit 11bc140481
8 changed files with 190 additions and 21 deletions

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -56,6 +56,7 @@ dependencies {
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("androidx.leanback:leanback:1.0.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

View File

@ -3,41 +3,48 @@ package com.example.androidlabs
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.LocationOn
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.androidlabs.homeScreen.CardItem.HotelScrollBar
import com.example.androidlabs.ui.theme.AndroidLabsTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AndroidLabsTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Greeting("Android")
}
}
HotelScrollBar()
}
}
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
AndroidLabsTheme {
Greeting("Android")
}
}

View File

@ -0,0 +1,113 @@
package com.example.androidlabs.homeScreen.CardItem
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LocationOn
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CardElevation
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.androidlabs.R
import com.example.androidlabs.ui.theme.AndroidLabsTheme
@Composable
fun Card (hotel: Hotel){
androidx.compose.material3.Card(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
shape = RoundedCornerShape(15.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 20.dp
) ) {
Box(
//modifier = Modifier.background(Color.Green)
) {
Row(
modifier = Modifier
//.background(Color.Yellow)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Image(
painter = painterResource(id = hotel.img),
contentDescription = "hotel",
contentScale = ContentScale.Fit,
modifier = Modifier
.padding(4.dp)
.size(150.dp)
)
Column(
modifier = Modifier
//.background(Color.Red)
.padding(start = 20.dp),
//horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(20.dp)
) {
Text(text = hotel.name, fontSize = 40.sp, fontWeight = FontWeight.Bold)
Row() {
Image(
imageVector = Icons.Filled.Star,
contentDescription = "location",
modifier = Modifier.size(20.dp)
)
Image(
imageVector = Icons.Filled.Star,
contentDescription = "location",
modifier = Modifier.size(20.dp)
)
Image(
imageVector = Icons.Filled.Star,
contentDescription = "location",
modifier = Modifier.size(20.dp)
)
Image(
imageVector = Icons.Filled.Star,
contentDescription = "location",
modifier = Modifier.size(20.dp)
)
Image(
imageVector = Icons.Filled.Star,
contentDescription = "location",
modifier = Modifier.size(20.dp)
)
}
Text(text = hotel.location)
}
Image(
imageVector = Icons.Filled.LocationOn,
contentDescription = "location",
modifier = Modifier.size(40.dp)
)
}
}
}
}
@Preview(showBackground = true)
@Composable
fun CardPreview() {
Card(Hotel("hotel", R.drawable.img, 5, "location"))
}

View File

@ -0,0 +1,11 @@
package com.example.androidlabs.homeScreen.CardItem
import android.media.Image
data class Hotel(
val name: String,
val img: Int,
val stars: Int,
val location: String
)

View File

@ -0,0 +1,26 @@
package com.example.androidlabs.homeScreen.CardItem
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.example.androidlabs.R
@Composable
fun HotelScrollBar() {
Column {
Card(Hotel("hotel", R.drawable.img, 5, "location"))
Card(Hotel("hotel", R.drawable.img, 5, "location"))
Card(Hotel("hotel", R.drawable.img, 5, "location"))
Card(Hotel("hotel", R.drawable.img, 5, "location"))
Card(Hotel("hotel", R.drawable.img, 5, "location"))
Card(Hotel("hotel", R.drawable.img, 5, "location"))
Card(Hotel("hotel", R.drawable.img, 5, "location"))
Card(Hotel("hotel", R.drawable.img, 5, "location"))
}
}
@Preview(showBackground = true)
@Composable
fun HotelPreview() {
HotelScrollBar()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
</vector>