【发布时间】:2021-11-01 11:17:46
【问题描述】:
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="Doctor Appointment"
app:titleTextColor="#fff"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="4dp"
android:background="@color/blue"
android:drawableLeft="@drawable/ic_action_logout"
android:text="Logout"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/myToolbar"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="SpeakableTextPresentCheck,SpeakableTextPresentCheck" />
</androidx.viewpager.widget.ViewPager>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="411dp"
android:layout_height="712dp"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MissingConstraints">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginTop="70dp"
android:background="@drawable/my_border"
android:text="save"
android:textColor="@color/blue"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button2"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="70dp"
android:background="@drawable/my_border"
android:text="close"
android:textColor="@color/blue" />
</RelativeLayout>
<RadioGroup
android:id="@+id/G1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
<RadioButton
android:id="@+id/R1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="By Speciality" />
<RadioButton
android:id="@+id/R2"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="By Doctor"/>
</RadioGroup>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="25dp"
android:src="@drawable/female_doctor" />
<TextView
android:id="@+id/Name1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_toEndOf="@+id/img2"
android:text="Dr. J. Anitha Ponmalar"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/degree1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Name1"
android:layout_marginTop="15dp"
android:layout_toEndOf="@+id/img2"
android:text="M.B.B.S., DCH, MD physiology"
android:textColor="#000000"
android:textSize="14sp" />
<TextView
android:id="@+id/branch1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/degree1"
android:layout_marginTop="15dp"
android:layout_toEndOf="@+id/img2"
android:text="Dermatology"
android:textColor="#000000"
android:textSize="14sp" />
<TextView
android:id="@+id/time1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="190dp"
android:layout_marginTop="99dp"
android:layout_toEndOf="@+id/img2"
android:text="Fee : 309" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
如何实现可单击的滚动视图,在单击滚动视图时我需要导航到另一个活动。这里我附上了图像,我在滚动视图中使用了图像和文本。在 java 文件中我使用了单选按钮单击.你能帮我用java代码使滚动视图可点击吗?我尝试使用点击监听器将滚动视图实现为可点击,但它不起作用。
【问题讨论】:
-
您可以将 clicklistener 添加到
ScrollView的子代,在您的情况下为LinearLayout。 -
ScrollView 滚动条 = (ScrollView)findViewById(R.id.scrollView); scroller.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Dermatology.this,Spec_Derm.class); startActivity(intent); } });您可以对此进行更改吗?