Видимость ScrollView - PullRequest
       23

Видимость ScrollView

0 голосов
/ 15 апреля 2011

Я использую два ScrollViews и хочу установить видимость одного как GONE или INVISIBLE, но когда я делаю это, следуя java-коду, приложение завершается. Если я делаю то же самое, используя Панорамирование свойств, в затмении это просто работает. Что не так?


Java-код:

public class Test extends Activity {

    List<ScrollView> sv;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        sv = new ArrayList<ScrollView>();

        sv.add((ScrollView)findViewById(R.id.scrollView1));
        sv.add((ScrollView)findViewById(R.id.scrollView2));

        sv.get(1).setVisibility(View.GONE);

        setContentView(R.layout.main);
    }
}

main.xml

<?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="fill_parent"
    android:gravity="fill_vertical">
    <ScrollView android:layout_height="wrap_content" android:id="@+id/scrollView1" android:layout_width="match_parent">
        <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/linearLayout1" android:orientation="vertical">
            <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
        </LinearLayout>
    </ScrollView>
    <ScrollView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/scrollView2">
        <TextView android:text="TextView" android:layout_width="match_parent" android:id="@+id/textView2" android:layout_height="match_parent"></TextView>
    </ScrollView>
</LinearLayout>

Ответы [ 2 ]

0 голосов
/ 17 декабря 2012

Прежде всего, вам нужно установить файл макета.

setContentView(R.layout.new_view);
sv = new ArrayList<ScrollView>();

sv.add((ScrollView)findViewById(R.id.scrollView1));
sv.add((ScrollView)findViewById(R.id.scrollView2));

sv.get(1).setVisibility(View.GONE);

Попробуйте, если у вас возникли ошибки, пожалуйста, напишите logcat.

0 голосов
/ 15 апреля 2011

у вас нет setContentview (yourLayout.xml)

он не сможет найти ViewById.

сделать findViewById ПОСЛЕ setContentView

...