ارسال پاسخ 
 
امتیاز موضوع:
  • 1 رأی - میانگین امتیازات: 5
  • 1
  • 2
  • 3
  • 4
  • 5
رخداد LongClick در برنامه نویسی اندروید
10-03-2018, 01:08 PM
ارسال: #1
رخداد LongClick در برنامه نویسی اندروید
در ابتدا یک Layout برای نمایش متن و عکس ایجاد می کنیم:

کد:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_gravity="right"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imgIcon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:gravity="center_vertical"
        android:src="@drawable/ic_launcher_background">

    </ImageView>
<TextView
    android:id="@+id/textitem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/colorTT"
    android:textSize="100px"
    />
</android.support.constraint.ConstraintLayout>

سپس در Layout اصلی اشیاء را جایگذاری می نماییم:

کد:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"
    tools:context=".MainActivity"
    android:layout_gravity="right"
    >

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/header"
        android:background="#FC9"
        android:orientation="horizontal">

        <Button
            android:paddingLeft="10dp"
            android:paddingStart="10dp"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/BtnAdd"
            android:layout_margin="4dp"
            android:textSize="18sp"
            android:textColor="#000"/>
        <EditText
            android:gravity="center"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/textInput"
            android:layout_toRightOf="@+id/Drive_Number"
            android:layout_margin="4dp"
            android:textSize="18sp"
            android:textColor="#000"/>
        <TextView
            android:paddingRight="10dp"
            android:paddingEnd="10dp"
            android:gravity="right"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/Drive_Time"
            android:layout_toRightOf="@+id/Drive_Distance"
            android:layout_margin="4dp"
            android:textSize="18sp"
            android:textColor="#000"/>
    </LinearLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="vertical"
        android:layout_below="@+id/header"
        android:textDirection="rtl"
        android:id="@+id/scrollableContents">

        <ListView
            android:id="@+id/lstv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textDirection="rtl"

            />

    </RelativeLayout>
    </RelativeLayout>
</android.support.constraint.ConstraintLayout>

یک Layout هم از قل به عنوان صفحه PopUP ایجاد کرده ایم:

کد:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_gravity="right"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textm1001"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        android:textColor="@color/colorAccent"
        android:textSize="100px"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraint