开发者

ScrollView Jumps into EditText

开发者 https://www.devze.com 2023-03-11 09:42 出处:网络
When I start my App, it automatically jumps into the first \"EditText\"-Box. I built in a Scroll Bar.

When I start my App, it automatically jumps into the first "EditText"-Box. I built in a Scroll Bar.

And when I remove the Scroll Bar, it doesn't jump into the "EditText"-Box.

Why does it jump in the "EditText"-Box? I don't like that it jumps into that Box. :/

Here the Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<TextView 
    android:id="@+id/textView1" 
    android:layout_height="wrap_content" 
    android:text="Brutto- oder Nettobetrag eingeben:" 
    android:layout_width="fill_parent">
</TextView>

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">

        <EditText 
            android:id="@+id/edt_betrag"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:inputType="numberDecimal"/>

        <RadioGroup 
            android:id="@+id/rg_art"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <RadioButton 
                android:id="@+id/rb_art_netto"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Netto" 
                android:checked="true" />

            <RadioButton 
                android:id="@+id/rb_art_brutto"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Brutto" />

            <TextView 
                android:id="@+id/textView2" 
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent" 
                android:text="Prozentsatz eingeben:">
            </TextView>

            <EditText 
                andr开发者_开发问答oid:layout_height="wrap_content" 
                android:layout_width="match_parent" 
                android:id="@+id/eigener_betrag"
                android:inputType="numberDecimal">
            </EditText>     

        </RadioGroup>

        <Button 
            android:id="@+id/Button01main" 
            android:text="Berechnen" 
            android:layout_height="50dip" 
            android:layout_width="fill_parent" 
            android:layout_gravity="center" android:layout_marginBottom="20dip">
        </Button>

        <Button 
            android:layout_height="wrap_content" 
            android:id="@+id/zurueck" 
            android:text="Zurück" 
            android:layout_gravity="left" 
            android:layout_width="150dip">
        </Button>

    </LinearLayout>
</ScrollView>


To solve this programmactcally you should code something like this.

    ScrollView scroll = (ScrollView)findViewById(R.id.my_scroll);
    scroll.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    scroll.setFocusable(true);
    scroll.setFocusableInTouchMode(true);
    scroll.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            return false;
        }
    });


I solved the problem by myself:

        android:focusable="true" 
        android:focusableInTouchMode="true">

That was the problem ;) Added at

    <ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
       android:focusable="true" 
            android:focusableInTouchMode="true">
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号