2013-07-23 2 views
3

XML이 완벽하게 작동하고 목록보기, 일련의 textviews, imageviews 및 버튼이 있습니다. 그런 다음 전체 레이아웃에 스크롤보기를 추가했습니다. Listview가 작동을 멈춘 다음 사용자 정의 클래스를 추가하여 작동하게했습니다. 이제 모든 것이 의도 한대로 작동하지만, 문제는 XML의로드시 레이아웃의 윗부분이 보이지 않는다는 것입니다. 맨 위로 스크롤해야합니다.ScrollView가 android에서 XML의 위쪽 부분을 표시하지 않습니다.

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/bg_default" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:id="@+id/navigation_layout" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/navigation" 
      android:baselineAligned="false" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="1" > 

       <TextView 
        android:id="@+id/app_name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:layout_gravity="center_horizontal|center_vertical" 
        android:textColor="#057afb" 
        android:textSize="19sp" 
        android:textStyle="bold" /> 
      </RelativeLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/navigation_layout1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/navigation_layout" 
      android:baselineAligned="false" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="1" 
       android:paddingTop="10dp" > 



       <ImageView 
        android:id="@+id/app_icon" 
        android:layout_width="75dp" 
        android:layout_height="75dp" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_marginLeft="23dp" 
        android:layout_marginTop="14dp" 
        android:scaleType="fitXY" 
        android:src="@drawable/ic_launcher" /> 

       <Button 
        android:id="@+id/btn_install" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignTop="@+id/app_icon" 
        android:layout_marginRight="36dp" 
        android:background="@drawable/list_apps_install_button_selector" /> 

       <TextView 
        android:id="@+id/txt_desc" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@+id/app_icon" 
        android:layout_below="@+id/app_icon" 
        android:text="desription goes here" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/txt_desc_long" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@+id/app_icon" 
        android:layout_below="@+id/app_icon" 
        android:text="desription goes here" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:visibility="gone"/> 

       <TextView 
        android:id="@+id/txtMore" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        android:layout_marginRight="14dp" 
        android:text="...More" 
        android:textColor="#057afb" /> 

      </RelativeLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/navigation_layout2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/navigation_layout1" 
      android:baselineAligned="false" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="1" > 

       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="fill_parent" 
        android:layout_height="2dp" 
        android:layout_alignParentLeft="true" 
        android:layout_below="@+id/txt_desc" 
        android:layout_marginTop="15dp" 
        android:background="@drawable/separator_app_details" /> 

       <TextView 
        android:id="@+id/textView3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@+id/information" 
        android:layout_below="@+id/information" 
        android:layout_marginLeft="50dp" 
        android:layout_marginTop="5dp" 
        android:text="@string/version" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:textColor="#929292" /> 

       <TextView 
        android:id="@+id/txt_version" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBaseline="@+id/textView3" 
        android:layout_alignBottom="@+id/textView3" 
        android:layout_marginLeft="22dp" 
        android:layout_toRightOf="@+id/textView3" 
        android:text="Small Text" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/textView5" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignRight="@+id/textView3" 
        android:layout_below="@+id/textView3" 
        android:text="@string/uploader" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:textColor="#929292" /> 

       <TextView 
        android:id="@+id/textView7" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@+id/textView5" 
        android:layout_below="@+id/textView5" 
        android:text="@string/updated" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:textColor="#929292" /> 

       <TextView 
        android:id="@+id/textView9" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignRight="@+id/information" 
        android:layout_below="@+id/textView7" 
        android:text="@string/size" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:textColor="#929292" /> 

       <TextView 
        android:id="@+id/textView11" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignRight="@+id/textView9" 
        android:layout_below="@+id/textView9" 
        android:text="@string/compatibility" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:textColor="#929292" /> 

       <TextView 
        android:id="@+id/txt_uploader" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/textView7" 
        android:layout_alignLeft="@+id/txt_version" 
        android:text="Small Text" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/txt_updated" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@+id/txt_uploader" 
        android:layout_below="@+id/txt_uploader" 
        android:text="Small Text" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/txt_size" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/textView11" 
        android:layout_alignLeft="@+id/txt_updated" 
        android:text="Small Text" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/txt_compat" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBaseline="@+id/textView11" 
        android:layout_alignBottom="@+id/textView11" 
        android:layout_alignLeft="@+id/txt_size" 
        android:text="Small Text" 
        android:textAppearance="?android:attr/textAppearanceSmall" /> 

       <TextView 
        android:id="@+id/information" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_marginLeft="14dp" 
        android:layout_marginTop="19dp" 
        android:text="@string/txt_info" 
        android:textColor="#000000" 
        android:textSize="19sp" /> 
      </RelativeLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/navigation_layout3" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/navigation_layout2" 
      android:layout_marginTop="15dp" 
      android:baselineAligned="false" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="1" > 

       <TextView 
        android:id="@+id/older_versions" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_marginLeft="14dp" 
        android:layout_marginTop="10dp" 
        android:text="@string/old" 
        android:textColor="#000000" 
        android:textSize="19sp" /> 

       <ListView 
        android:id="@+id/listView1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_below="@+id/older_versions" 
        android:divider="@null" > 
       </ListView> 
      </RelativeLayout> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/TextView01" 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignTop="@+id/navigation_layout3" 
      android:background="@drawable/separator_app_details" /> 
    </RelativeLayout> 

</ScrollView> 

이 스크롤보기와 목록보기 기능에서 모두를 만들기 위해 쓰여진 클래스는 다음과 같습니다 ScrollView doesn't show top part 이것은 XML 파일입니다 내 문제는이 같은 여전히 ​​제공하는 솔루션이 작동하지 않는 것입니다 동시에 :

public class Utility { 

    public static void setListViewHeightBasedOnChildren(ListView listView) { 
     ListAdapter listAdapter = listView.getAdapter(); 
     if (listAdapter == null) { 
      // pre-condition 
      return; 
     } 

     int totalHeight = 0; 
     for (int i = 0; i < listAdapter.getCount(); i++) { 
      View listItem = listAdapter.getView(i, null, listView); 
      listItem.measure(0, 0); 
      totalHeight += listItem.getMeasuredHeight(); 
     } 

     ViewGroup.LayoutParams params = listView.getLayoutParams(); 
     params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
     listView.setLayoutParams(params); 
    } 

} 

wrong image correct image

+0

'ScrollView'를 열 때 정확히 어떤 부분이 표시됩니까? (일부 스크린 샷을 붙여 넣기 만하면됩니까) 감사합니다 – g00dy

+0

편집 된 질문을 참조하십시오, 왼쪽 이미지가 잘못된 하나, 오른쪽 이미지가 올바른 방법이어야합니다! – TharakaNirmana

+0

이것을'OnCreate' 메쏘드에 넣으십시오 :'final ScrollView scrollview = ((ScrollView) findViewById (R.id.scrollview)); scrollview.post (새의 Runnable() { @Override 공공 무효 실행() { scrollview.fullScroll (ScrollView.FOCUS_UP) } }); 안녕하세요이 일 – g00dy

답변

6

OnCreate() 방법이 넣어 :

final ScrollView scrollview = ((ScrollView) findViewById(R.id.scrollview)); scrollview.post(new Runnable() { 
    @Override public void run() { 
    scrollview.fullScroll(ScrollView.FOCUS_UP); 
    } 
}); 

위의 코드는 ScrollView의 스크롤을 강제로 위로하는 방법을 제공합니다. 이 동작은 심지어 일부 레이아웃 등의 weight 속성으로 인해 발생할 수 있습니다. 위의 "디버깅"은 위의 솔루션을 적용하는 데 더 많은 시간이 걸릴 것이며 각 시간이 처음 스크롤을 방해하는 것을 알 수 있다고 보장 할 수는 없습니다 위치.

+0

솔루션에 대한 의견을 보내 주시겠습니까? 그리고 문제가 해결 된 이유는 무엇입니까? 나는 물론 당신이 초점을 강제로 볼 수 있지만 그가 어쨌든 원한다면 사용자가 위로 스크롤 할 수 없어야합니까? 문제를 일으키는'ScrollView'의 선언을 생략 한 것입니까? – Eric

+0

답변에 몇 가지 정보를 붙여 넣습니다. 맞습니다. 그러나 사용자가 "어쨌든 원한다면 사용자가 스크롤 할 수 없으며"ScrollView의 선언이 누락되어서는 안됩니까? - 어떤 선언을 말하는 겁니까? – g00dy

+0

저에게 준 솔루션을 적용하기 전에, 상단 부분이없는 페이지가로드됩니다. 이는 일반적인 방법은 아닙니다. 그러나 솔루션을 사용하면보기가 정상적으로 작동하고 상단 부분이 먼저로드 된 다음 사용자가 점차 아래로 스크롤 할 수 있으며 끝까지 도달하면 다시 올 수 있습니다. – TharakaNirmana

관련 문제