我做了一个简单的活动,因为我使用了scrollView但它不工作并显示错误,所以我已经删除了scrollView..Friends我需要的是所有菜单都应该包含在scrollView ..请任何人都可以建议我wher7e我应该放置我的活动中的"scrollView"标签.
我的活动如下:

主menu.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/kevingreen" android:background="#000" android:layout_weight="1"/>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.3"
android:background="#fffff3"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="fill_parent"
android:layout_height="190dp" >
<LinearLayout
android:id="@+id/linearLayout6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageButtonVideos"
android:layout_width="fill_parent"
android:layout_height="115dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#0000"
android:scaleType="centerCrop"
android:src="@drawable/balcony_pic" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Videos"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/ImageButtonTraining2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#0000" …Run Code Online (Sandbox Code Playgroud) 我已经看过一些论坛,但是这些技巧对我来说不起作用。
我有以下代码:
scrollview = (ScrollView)v.findViewById(R.id.scrollView);
scrollview.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
@Override
public void onScrollChanged() {
Log.d(MainActivity.TAG, "scroll ch: "+scrollview.getScrollY()+"/"+scrollview.getChildAt(0).getHeight());
}
});
Run Code Online (Sandbox Code Playgroud)
在我的layout.xml中
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="@+id/principal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/horiz"
android:orientation="vertical"
android:showDividers="end|middle" >
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
当我向下滚动到最后一个时,我得到的getScrollY()小于getChildAt(0).getHeight()。
我怎样才能使两者的总大小相同?
我有一个CoordinatorLayout和它里面,两个FloatingActionButton和它们下面一个ScrollView.
问题是即使我可以FloatingActionButtons在屏幕上看到我也无法点击它们.我怀疑那是因为所有onTouch事件都是在处理ScrollView
这是我的布局xml(这可能非常糟糕,所以欢迎任何提示):
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Note: that 80dp padding is:
main_padding + fab_size + 8dp = 80dp
16dp + 56dp + 8dp = 80dp
and it was the only way I could think to add padding
between my FABs
I tried to use app:layout_anchor but my 2
FABs had no padding between them... -->
<android.support.design.widget.FloatingActionButton
style="@style/RefreshFab"
android:id="@+id/fab_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="80dp"
android:layout_marginEnd="16dp" …Run Code Online (Sandbox Code Playgroud) 我已经尝试过全面搜索,但我似乎无法想出这个.基本上,我有一个Scrollview的布局和里面的元素.我想在滚动视图中放置一个按钮,它位于末尾/底部,只有当你一直滚动到底部时才能看到它.我试过这样做:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/topcontainer">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar_review"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:title="Review Your Massage">
</android.support.v7.widget.Toolbar>
<include layout="@layout/card_review"/>
</LinearLayout>
<Button
android:id="@+id/buttonReview"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent"
android:text="@string/book"
android:layout_below="@+id/topcontainer"
/>
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
按钮确实位于底部,但下方有空间.如果我在分辨率更高的手机上运行应用程序,按钮将几乎位于屏幕中间.我怎么能这样做,无论它的分辨率如何始终保持在最低点?
我心中已经有了一个Button内部ScrollView。
<ScrollView>
<LinearLayout>
...
<Button/>
...
<LinearLayout/>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我正在使用此按钮来记录语音。当它捕获到MotionEvent.ACTION_DOWN事件时,我开始重新编码,并在MotionEvent.ACTION_DOWN事件停止时将其停止。
buttomRecord.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
startRecording();
return true;
}
else if(event.getAction() == MotionEvent.ACTION_UP){
stopRecording();
return true;
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
当用户录制语音,如果这个问题是ScrollView滚动向上或向下,该按钮就会失去焦点,从来没有抓MotionEvent.ACTION_UP事件。
怎样才能锁定焦点Button,而我拿着它或禁用ScrollView滚动?
android ontouchlistener android-scrollview android-button motionevent
在我的Fragment的布局中,我有一个带有LinearLayout的ScrollView
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Other views -->
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
所以我需要创建和分享scrollview的整个内容的图片.我试过的所有解决方案都只截取可见区域的截图,而不是整个scrollview内容.我能怎么做?
我正在尝试在 ScrollView 中添加约束布局,但布局没有滚动我已经尝试过的:
-> 在nestedscrollview 中放置约束布局
-> 将滚动视图放在另一个约束布局中并设置 height = "0dp", constraintTop_toTopOf = "parent", constraintTop_toTopOf = "bottom"
-> 添加 android:isScrollContainer="true"
这是代码:
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvItemName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="Large antique wardrobe"
android:textColor="@color/black1"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="16dp"
android:text="@string/transit_charge"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvItemName"
app:layout_constraintTop_toBottomOf="@+id/tvItemName" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="16dp"
android:text="@string/required_by"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toEndOf="@+id/textView10"
app:layout_constraintTop_toBottomOf="@+id/tvItemName" />
<TextView
android:id="@+id/tvPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp" …Run Code Online (Sandbox Code Playgroud) 我正在制作一个简单的转换器应用程序.尝试转换输入并在下面的EditTexts中显示它,但我的ScrollView不起作用.(字面意思什么也没做)我使用ConstraintLayout作为root,我在其中有LinearLayout,它是ScrollView的根.
那么,我在这里错过了什么?
<?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="gns.converter.LengthConversion">
<Spinner
android:id="@+id/spinnerTo"
android:layout_width="120dp"
android:entries="@array/spinnerLengthItems"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/textFrom"
android:layout_marginLeft="42dp"
app:layout_constraintBaseline_toBaselineOf="@+id/textFrom"
android:layout_marginStart="42dp" />
<EditText
android:id="@+id/textFrom"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:textSize="20sp"
android:hint="(From) 0"
android:gravity="right"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="44dp"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="16dp" />
<Button
android:id="@+id/buttonConvert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="78dp"
android:layout_marginTop="13dp"
android:text="CONVERT"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textFrom"
android:layout_marginStart="78dp" />
<Button
android:id="@+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="42dp"
android:layout_marginTop="23dp"
android:text="CLEAR"
app:layout_constraintLeft_toRightOf="@+id/buttonConvert"
app:layout_constraintTop_toBottomOf="@+id/spinnerTo"
android:layout_marginStart="42dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="495dp"
android:orientation="horizontal"
android:layout_marginRight="8dp"
android:background="#e40707"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="30dp"
app:layout_constraintTop_toBottomOf="@+id/buttonConvert"
app:layout_constraintHorizontal_bias="0.0">
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> …Run Code Online (Sandbox Code Playgroud) 所以从调试和评论出来的事情我得出结论,这个程序的问题是在addTextView()方法中.我完全不知道问题出在哪里.我的猜测是在我尝试添加到TextView的布局中.非常感谢你提前帮助.
public class Books extends Activity{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.books);
addTextView("Hello World");
}
public void addTextView(String text)
{
ScrollView viewport = (ScrollView)findViewById(R.id.books);
TextView textview= (TextView)new TextView(this);
textview.setText(text);
//textview.setLayoutParams(new ScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
viewport.addView(textview, new ScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
public void addButton(String text)
{
ScrollView scrollview = (ScrollView)findViewById(R.id.books);
Button btnTag = (Button)new Button(Books.this);
btnTag.setLayoutParams(new ScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btnTag.setText(text);
scrollview.addView(btnTag);
}
}
Run Code Online (Sandbox Code Playgroud) android ×9
scrollview ×2
xml ×2
android-xml ×1
dynamic ×1
motionevent ×1
screenshot ×1
textview ×1