ConstraintLayout – komponentalarga yoki oynaga joylashtiriladi bu uning o`lchamini o`zgartirish imkoniyatini beradi.
View — bu ekranda ko’rinadigan barcha elementlarni o’zida saqlaydigan UI (foydalanuvchi interfeys) qatlami.
2-rasm. Joylar ko`rinishi.
Joylar ko`rinishining XML kodi:
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"
android:paddingBottom="20dp"
tools:context=".City_Informatin">
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:background="#686868"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView" />
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView12" />
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:fontFamily="@font/lato_black"
android:text="Asosiy aylanadigan joylar"
android:textColor="@color/black"
android:textSize="22sp"
app:layout_constraintStart_toStartOf="@+id/textView10"
app:layout_constraintTop_toBottomOf="@+id/view" />
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:background="#686868"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView10" />
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/lato_black"
android:text="Aylanadigan joylar"
android:textColor="#730B04"
android:textSize="22sp"
app:layout_constraintStart_toStartOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/textView9" />
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:fontFamily="@font/lato_black"
android:text="3 Days Tour"
android:textColor="@android:color/holo_green_dark"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="@+id/button2"
app:layout_constraintTop_toBottomOf="@+id/button2" />
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:backgroundTint="#3F51B5"
android:elevation="20dp"
android:fontFamily="@font/lato_black"
android:outlineAmbientShadowColor="#3F51B5"
android:outlineSpotShadowColor="#3F51B5"
android:text="Manzilni xaritada ko`rish"
android:textAllCaps="false"
android:textSize="18sp"
app:cornerRadius="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView6"
tools:ignore="MissingConstraints" />
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="@+id/recyclerView"
app:layout_constraintStart_toStartOf="@+id/recyclerView"
app:layout_constraintTop_toBottomOf="@+id/view2">
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="2"
android:backgroundTint="#E91E63"
android:fontFamily="@font/lato_black"
android:text="Restaurants"
android:textAllCaps="false"
android:textSize="18sp"
app:cornerRadius="10dp"
app:icon="@drawable/baseline_restaurant_menu_24" />
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="2"
android:backgroundTint="#4CAF50"
android:fontFamily="@font/lato_black"
android:text="Hotels"
android:textAllCaps="false"
android:textSize="18sp"
app:cornerRadius="10dp"
app:icon="@drawable/baseline_hotel_24" />
android:id="@+id/cardView6"
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardCornerRadius="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
android:id="@+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
app:srcCompat="@drawable/img_5" />
MainActivity klasi:
package com.example.kursishi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterViewFlipper;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
AdapterViewFlipper flipper;
ArrayList flipper_data;
AdapterFlipper_BaseAdapter flipper_baseadapter;
CardView shakhi_zinda;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flipper = findViewById(R.id.adapter_flipper_home); //main flipper of the home which would be shown in application
flipper_data = new ArrayList<>();
//Adding items to flipper_data arraylist.
flipper_data.add(new AdapterFlipperModel("Bibikhanim mechet", "Samarkand", R.drawable.img)); //setting values to the items which were in the constructor of model adpater java class
flipper_data.add(new AdapterFlipperModel("Ulugbek observatory", "Samarkand", R.drawable.img_1));
flipper_data.add(new AdapterFlipperModel("Guri Amir Mausoleum", "Samarkand", R.drawable.img_2));
flipper_data.add(new AdapterFlipperModel("Registan", "Samarkand", R.drawable.img_3));
flipper_data.add(new AdapterFlipperModel("Boqiy Shahar", "Samarkand", R.drawable.img_4));
flipper_data.add(new AdapterFlipperModel("Shahi Zinda", "Samarkand", R.drawable.img_5));
flipper_baseadapter = new AdapterFlipper_BaseAdapter(this, flipper_data);
flipper.setAdapter(flipper_baseadapter);
flipper.setAutoStart(true);
flipper.setFlipInterval(3000);
shakhi_zinda = findViewById(R.id.shakh);
shakhi_zinda.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, City_Informatin.class));
}
});
}
}
Do'stlaringiz bilan baham: