Android向下滚动不起作用

时间:2017-07-29 14:15:47

标签: android

我试图向下滚动到我的一个相对布局。问题是向下滚动内的所有文本都消失了(从文本视图4到结尾 - notes0-nite4)。如果我把代码放在主要活动xml的开头,它的工作正常 - 但是我想只在一个布局中使用向下滚动。 我添加了我的代码图片

我使用了以下链接,但没有帮助

How to make my layout able to scroll down? Why My ScrollView not working Properly?

enter image description here

<ScrollView
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id="@+id/scroll"
    android:orientation="vertical"
    android:visibility="invisible"
    >

<LinearLayout
    android:id="@+id/howToPlayLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >



    <TextView
        android:id="@+id/howToPlayText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="center_horizontal"
        android:text="@string/how_to_play"
        android:textColor="@android:color/black"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="4dp"
        android:text="@string/insert_each_letter_in_the_right_cell_so_when_the_puzzle_is_completed_every_row_and_column_contains_a_real_4_letters_word_4_words_horizontally_and_4_words_vertically_top_to_bottom"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="17sp"
        android:textStyle="italic" />



    <TextView
        android:id="@+id/textView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:text="@string/share_a_freind_button_is_used_to_get_friend_s_help_via_whatsapp_facebook_twitter"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="17sp"
        android:textStyle="italic" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:text="@string/lamp_button_can_give_you_a_free_hint_after_watching_a_video_ad"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="17sp"
        android:textStyle="italic" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:text="@string/x_button_is_used_in_order_to_delete_a_letter_which_you_located_wrongly_in_the_puzzle"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="17sp"
        android:textStyle="italic" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:text="@string/the_puzzle_may_also_contains_names"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="17sp"
        android:textStyle="italic"
        tools:textStyle="italic" />

    <Button
        android:id="@+id/button37"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
        android:background="@android:color/holo_blue_dark"
        android:onClick="backToGame"
        android:text="@string/back_to_game1"
        android:textColor="@android:color/white"
        android:textSize="17sp" />

    <Button
        android:id="@+id/button39"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
        android:background="@android:color/holo_blue_dark"
        android:onClick="backToMenu"
        android:text="@string/back_to_menu1"
        android:textColor="@android:color/white"
        android:textSize="17sp" />

    <!-- End How to play layout-->


</LinearLayout>
</ScrollView>




 @Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater menuInflater=getMenuInflater();
    menuInflater.inflate(R.menu.main_menu,menu );

    return super.onCreateOptionsMenu(menu);
} // End onCreateOptionsMenu



@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()){

        case R.id.howToPlay:
            ScrollView mScrollView=(ScrollView)findViewById(R.id.scroll);
            mScrollView.setVisibility(View.VISIBLE);

            howToPlayLayout.setVisibility(LinearLayout.VISIBLE);
            note0.setVisibility(View.VISIBLE);
            note1.setVisibility(View.VISIBLE);
            note2.setVisibility(View.VISIBLE);
            note3.setVisibility(View.VISIBLE);
            note4.setVisibility(View.VISIBLE);
            titleHowToPlay.setVisibility(View.VISIBLE);


enter code here

1 个答案:

答案 0 :(得分:0)

您尚未提及LinearLayout的方向

<LinearLayout
    android:id="@+id/howToPlayLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"              //Here
    >

默认情况下它是水平,所以发生的情况是你的第一个TextView howToPlayText占用整个宽度,然后其余的不再可见。