我一直在搜索很多有关如何实现按钮的 onClick 方法的信息,该按钮允许转到大型(可滚动)布局的顶部,但我没有找到任何文档。有什么办法可以做到这一点吗?
我有包含三个片段的 ViewPager,其中一个是 FrameLayout,里面有 ScrollView:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</ScrollView>
<Button
android:id="@+id/buttonRemove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_button_red"
android:layout_gravity="bottom"
android:layout_margin="4dp"
android:text="@string/button_remove_last_round"
android:textColor="#ffffff"
android:textSize="24sp"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
如果我滑过按钮,它就可以工作。但是如果我在 ScrollView 上滑动,它不起作用,只能向上/向下滚动
编辑:我试图覆盖 Scrollview 的 OnTouchEvent:
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
touchX = ev.getX();
touchY = ev.getY();
return super.onTouchEvent(ev);//if I change it to 'break', then only swipe works, but no scroll
case MotionEvent.ACTION_MOVE:
if(Math.abs(touchX-ev.getX())<40){
return super.onTouchEvent(ev);//Scroll works perfectly
}else{
return false;//Scroll disabled, but swipe still …Run Code Online (Sandbox Code Playgroud) Spinner 的“骨架”在向上滚动时显示在另一个布局后面。当我向上滚动 Spinner 的箭头并显示下划线时。我希望它像隐藏在另一个布局的后面一样隐藏它。
我有两个 ConstraintLayout 第二个用于 ScrollView。
这是我的 XML 的一部分。
<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"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="159dp">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="7dp"
android:text="Cummulative GPA: 0.00"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"/>
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3"
app:layout_constraintVertical_bias="0.0">
<TextView
android:id="@+id/fenn1"
style="@style/InputLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fenn 1"
app:layout_constraintBottom_toTopOf="@+id/spinner"
app:layout_constraintLeft_toLeftOf="@+id/spinner"/>
<Spinner
android:id="@+id/spinner"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="8dp"
android:layout_marginTop="55dp"
app:layout_constraintLeft_toLeftOf="parent" …Run Code Online (Sandbox Code Playgroud) 我试图在滚动视图处于空闲状态期间隐藏按钮。该按钮应该仅在滚动时间内不可见。(其余时间按钮应该可见)
scrollView.setOnScrollChangeListener(new ScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollX == scrollY) {
Button.setVisibility(View.VISIBLE);
} else if ((scrollY > oldScrollY)) {
Button.setVisibility(View.INVISIBLE);
}
}
});
Run Code Online (Sandbox Code Playgroud) 我有这样的视图层次结构
ScrollView
ConstraintLayout
ImageView
LinearLayout
TextView
TextView
TextView
...
Run Code Online (Sandbox Code Playgroud)
我想要实现的是 ImageView 在垂直方向上占据了可见屏幕的 65%...的可见区域。
为了得到这样的东西,最好的方法是什么?
源代码:
<ScrollView
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"
android:fillViewport="true"
tools:context=".MainActivity">
<android.support.constraint.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:src="@drawable/rain"
app:layout_constraintHeight_percent=".65"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/header">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AAAAAA"
android:textSize="50dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BBBB"
android:textSize="50dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CCCCC"
android:textSize="50dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DDDDD"
android:textSize="50dp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
提前致谢
android android-layout android-scrollview android-coordinatorlayout
以极快的速度到达 Scrollview 的末尾时有动画。当向下滚动到达末尾时,动画基本上将 ScrollView 向上拉,表明它是该视图的结尾。我怎样才能禁用它?
我的情况是 ScrollView 位于另一个具有深色背景的视图之上,并且该动画会破坏它。
我做了一个简单的布局xml文件.我一直在解决我的问题.我正在使用scrolview,linearlayout和tableview.我有一个顶栏,它被锁在顶部.它永远不会移动.在中间,我有一个scrollview,我需要将我的最后一个linearlayout作为页脚放在底部,如果用户向下滚动,我不希望它消失.我希望它被锁定在那里.
这是我的代码
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:background="@drawable/gradient"
android:gravity="center">
.......
</TableRow>
</TableLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/sw_layout"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#EEEEEE" >
<TableRow
android:id="@+id/tableRowDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
..........
</TableRow>
</TableLayout>
/*****************************************/
/* I want this to be footer at the bottom*/
/*****************************************/
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn_date"
android:layout_height="35dp"
android:padding="5dp"
android:drawableLeft="@drawable/calendar"
android:text="Tarih" />
<Button
android:id="@+id/btn_converter"
android:layout_height="35dp"
android:padding="5dp"
android:drawableLeft="@drawable/calendar"
android:text="Hesap" />
</LinearLayout>
/*****************************************/
/* I want …Run Code Online (Sandbox Code Playgroud) 我正在尝试以编程方式在Android中滚动HorizontalScrollView.
但是我刚刚找到了这个方法:
scroll.fullScroll(View.FOCUS_DOWN)
而且我期待将视图滚动到恰好中间.
有提示吗?
我知道有一种方法可以滚动到一个确切的位置:
setScrollX但参数应该以某种方式计算我不知道.
我无法在ScrollView下看到最顶层的视图.我已将scrollview放在Relative布局下.ScrollView有一个子布局,即线性布局,它有一些系列的按钮.问题是我无法看到ScrollView中存在的最顶层视图.
下面是布局xml代码.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#217d27"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:onClick="backPressed"
android:text="Back"
android:textColor="#000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:text="Heading Text"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:onClick="homeButtonClicked"
android:text="Home"
android:textColor="#000" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadingEdge="none"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#fff"
android:orientation="vertical" >
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button 1"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 2"
android:textColor="@color/black" />
<Button
android:layout_width="200dp" …Run Code Online (Sandbox Code Playgroud) 我已将滑动刷新布局作为顶级父节点附加,以向用户提供下拉刷新选项.
所以当我向下滚动时,我无法滚动,自动下拉选项开始加载.
我已经搜索了一些关于同一问题的堆栈溢出问题.他们说是根据列表视图当前索引监听滚动并禁用下拉选项.
我试着听听.但是当我向下滚动时我无法听到任何事件.
我的列表视图对象:
mListView = (ListView) getView().findViewById(android.R.id.list);
Run Code Online (Sandbox Code Playgroud)
谁能帮帮我吗.任何其他有趣的解决方案或解决.