2

This is my .xml file where I have used two scrollview,in Input Edittext and onether in output TextView. What is wrong here...It is not working in android device.

Another problem is that when I turn my device it only shows the input text area. The output text area goes down.I want to see the half screen of input and half screen of output area.

How to fix it??

Thanks

  <?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:orientation="vertical" >

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="35dp"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/test"
        android:layout_width="60dp"
        android:layout_height="38dp"
        android:text="@string/test" />

    <Button
        android:id="@+id/rdf"
        android:layout_width="60dp"
        android:layout_height="38dp"
        android:text="@string/rdf" />

    <Button
        android:id="@+id/load"
        android:layout_width="75dp"
        android:layout_height="38dp"
        android:text="@string/load" />

    <Button
        android:id="@+id/clear"
        android:layout_width="60dp"
        android:layout_height="38dp"
        android:text="@string/clear" />

    <Button
        android:id="@+id/close"
        android:layout_width="fill_parent"
        android:layout_height="38dp"
        android:text="@string/close" />

  </LinearLayout>

   <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/input"
            android:layout_width="0dp"
            android:layout_height="175dp"
            android:layout_weight="1"
            android:background="#fff"
            android:ems="10"
            android:gravity="top|left"
            android:textSize="14dp"
            android:inputType="textMultiLine" >

            <requestFocus />
        </EditText>
    </LinearLayout>
   </ScrollView>

   <Button
    android:id="@+id/run"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/run" />

   <ScrollView
    android:id="@+id/scrollView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/output"
            android:layout_width="match_parent"
            android:layout_height="225dp"
            android:background="#fff"
            android:text="@string/output"
            android:textColor="#1e90ff" />
    </LinearLayout>
 </ScrollView>

</LinearLayout>
2
  • Why do you want scroll a textview and a edittext?
    – amp
    Commented May 20, 2012 at 0:31
  • @amp....well i have load button which load a file into edittext and if i execute run btn...the result ll show in textview.
    – user1387408
    Commented May 20, 2012 at 10:40

2 Answers 2

0

Try setting layout_weight=1 and layout_height=0dp for the two scroll views instead of their contents.

0
0

What is wrong here...It is not working in android device.

That's pretty vague. What were your expectations? What isn't working? In other words, please be a little more specific.

However, based on the layout code given, here are some recommendations:

  1. Avoid hardcoding the size of views. You cannot make assumptions about screen size with the large variety of screen sizes, densities and devices out there. Also, even if you're able to make the layout look nice in portrait mode, it'll probably be not even close to that in landscape.
  2. If you're going to put just a single View in a ScrollView, there's no need to wrap it in a ViewGroup container; just set the View directly, without nesting it again and added an extra layer of complexity to the view hierarchy.
  3. There's no need to wrap a TextView or EditText with a ScrollView, as both views are scrollable by itself.

Regarding your second question: you can prevent Android from extracting all UI components when there's little layout estate left with the keyboard popped up. You'll need to set the IME_FLAG_NO_EXTRACT_UI flag on the EditText, or in xml: android:imeOptions="flagNoExtractUi".

I do like to point out that there's a reason Android has this behaviour by default. In most cases it hardly makes sense to force a tiny part of the UI to be visible, even more as whatever is being typed by the user is probably what really matters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.