1

소셜 네트워크에 대한 클라이언트의 스크롤 가능한 프로필을 만들려고합니다.ScrollView 내 RelativeLayout 및 ListView

여기 내 레이아웃입니다 :

<android.support.v4.widget.SwipeRefreshLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/swipe_container" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:id="@+id/RelativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <RelativeLayout 
      android:id="@+id/user_profile" 
      android:layout_width="fill_parent" 
      android:layout_height="440dp" 
      android:layout_alignParentTop="false" 
      android:layout_centerHorizontal="true"> 

      <ImageView 
       android:id="@+id/fragment_user_profile_avatar" 
       android:layout_width="fill_parent" 
       android:layout_height="300dp" 
       android:scaleType="centerCrop" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 

      <TableLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#0277BD" 
       android:layout_below="@+id/fragment_user_profile_avatar" 
       android:layout_alignParentLeft="false" 
       android:layout_alignParentStart="false" 
       android:layout_alignParentBottom="false" 
       android:id="@+id/tableLayout"> 

       <TableRow 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 
        <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_friends_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

         <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_friends_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/friends" 
          android:fontFamily="sans-serif-light" /> 

         <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_friends" android:layout_width="wrap_content" android:layout_height="wrap_content" 
          android:fontFamily="sans-serif-light" /> 
        </LinearLayout> 
        <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_followers_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

         <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_followers_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/followers" 
          android:fontFamily="sans-serif-light" /> 

         <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_followers" android:layout_width="wrap_content" android:layout_height="wrap_content" 
          android:fontFamily="sans-serif-light" /> 
        </LinearLayout> 
        <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_groups_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

         <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_groups_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/groups" 
          android:fontFamily="sans-serif-light" /> 

         <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_groups" android:layout_width="wrap_content" android:layout_height="wrap_content" 
          android:fontFamily="sans-serif-light" /> 
        </LinearLayout> 
       </TableRow> 

       <TableRow 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 

        <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_photos_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

         <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_photos_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/photos" 
          android:fontFamily="sans-serif-light" /> 

         <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_photos" android:layout_width="wrap_content" android:layout_height="wrap_content" 
          android:fontFamily="sans-serif-light" /> 
        </LinearLayout> 
        <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_videos_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

         <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_videos_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/videos" 
          android:fontFamily="sans-serif-light" /> 

         <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_videos" android:layout_width="wrap_content" android:layout_height="wrap_content" 
          android:fontFamily="sans-serif-light" /> 
        </LinearLayout> 
        <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_audios_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

         <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_audios_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/audios" 
          android:fontFamily="sans-serif-light" /> 

         <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_audios" android:layout_width="wrap_content" android:layout_height="wrap_content" 
          android:fontFamily="sans-serif-light" /> 
        </LinearLayout> 
       </TableRow> 
      </TableLayout> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:id="@+id/user_name" 
       android:textColor="#ffffffff" 
       android:textSize="34sp" 
       android:layout_above="@+id/age_city" 
       android:layout_centerHorizontal="true" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="#ffffffff" 
       android:id="@+id/online_status" 
       android:textSize="15sp" 
       android:layout_alignBottom="@+id/fragment_user_profile_avatar" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="35dp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:id="@+id/age_city" 
       android:textColor="#FFFFFFFF" 
       android:textSize="16sp" 
       android:layout_above="@+id/online_status" 
       android:layout_centerHorizontal="true" /> 
     </RelativeLayout> 

     <ExpandableListView 
      android:id="@+id/expandable_list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:cacheColorHint="#00000000" 
      android:listSelector="@android:color/transparent" 
      android:textColor="@android:color/white" 
      android:transcriptMode="normal" 
      android:fastScrollEnabled="false" 
      android:footerDividersEnabled="false" 
      android:headerDividersEnabled="false" 
      android:layout_below="@+id/user_profile" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="false" 
      android:layout_alignParentTop="false" 
      android:layout_alignWithParentIfMissing="false" 
      android:layout_alignParentRight="false" 
      android:layout_alignParentBottom="false" /> 

    </RelativeLayout> 
</ScrollView> 

을 그리고 난 내 응용 프로그램을 실행할 때, 나는 나의 ListView을 이동하지만, 레이아웃 user_profile로 단지 그 자리에 머물 수 있습니다. 그러나 나는 그것도 스크롤 가능하게하고 싶다. 도와주세요. 미리 감사드립니다.

편집

당신은 사람 놀라운! 도와 주셔서 대단히 감사합니다. 지금은 꼭해야 할 일입니다! 모든

+1

ListView를 ScrollView 내부에 두지 마십시오. 그것을 가지고 밖으로 시도하십시오. –

+0

@ GokhanArik, ok,하지만 어떻게? 나는 노력하고 있지만 화면을 채우는 relativelayout을 가진 scrollview – dennes544

+0

제발, 아무도! – dennes544

답변

3

user_profile.xml

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/user_profile" 
     android:layout_width="fill_parent" 
     android:layout_height="440dp" 
     android:layout_alignParentTop="false" 
     android:layout_centerHorizontal="true"> 

     <ImageView 
      android:id="@+id/fragment_user_profile_avatar" 
      android:layout_width="fill_parent" 
      android:layout_height="300dp" 
      android:scaleType="centerCrop" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <TableLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#0277BD" 
      android:layout_below="@+id/fragment_user_profile_avatar" 
      android:layout_alignParentLeft="false" 
      android:layout_alignParentStart="false" 
      android:layout_alignParentBottom="false" 
      android:id="@+id/tableLayout"> 

      <TableRow 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_friends_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

        <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_friends_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/friends" 
         android:fontFamily="sans-serif-light" /> 

        <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_friends" android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:fontFamily="sans-serif-light" /> 
       </LinearLayout> 
       <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_followers_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

        <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_followers_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/followers" 
         android:fontFamily="sans-serif-light" /> 

        <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_followers" android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:fontFamily="sans-serif-light" /> 
       </LinearLayout> 
       <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_groups_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

        <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_groups_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/groups" 
         android:fontFamily="sans-serif-light" /> 

        <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_groups" android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:fontFamily="sans-serif-light" /> 
       </LinearLayout> 
      </TableRow> 

      <TableRow 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

       <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_photos_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

        <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_photos_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/photos" 
         android:fontFamily="sans-serif-light" /> 

        <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_photos" android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:fontFamily="sans-serif-light" /> 
       </LinearLayout> 
       <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_videos_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

        <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_videos_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/videos" 
         android:fontFamily="sans-serif-light" /> 

        <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_videos" android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:fontFamily="sans-serif-light" /> 
       </LinearLayout> 
       <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@+id/header_user_profile_audios_container" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="33.0" style="?android:attr/borderlessButtonStyle"> 

        <TextView android:textSize="14.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_audios_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="-2.0dip" android:text="@string/audios" 
         android:fontFamily="sans-serif-light" /> 

        <TextView android:textSize="26.0sp" android:textColor="#ffffffff" android:id="@+id/fragment_user_profile_audios" android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:fontFamily="sans-serif-light" /> 
       </LinearLayout> 
      </TableRow> 
     </TableLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:id="@+id/user_name" 
      android:textColor="#ffffffff" 
      android:textSize="34sp" 
      android:layout_above="@+id/age_city" 
      android:layout_centerHorizontal="true" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#ffffffff" 
      android:id="@+id/online_status" 
      android:textSize="15sp" 
      android:layout_alignBottom="@+id/fragment_user_profile_avatar" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="35dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:id="@+id/age_city" 
      android:textColor="#FFFFFFFF" 
      android:textSize="16sp" 
      android:layout_above="@+id/online_status" 
      android:layout_centerHorizontal="true" /> 
    </RelativeLayout> 

list_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.SwipeRefreshLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/swipe_container" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

    <ExpandableListView 
     android:id="@+id/expandable_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:cacheColorHint="#00000000" 
     android:listSelector="@android:color/transparent" 
     android:textColor="@android:color/white" 
     android:transcriptMode="normal" 
     android:fastScrollEnabled="false" 
     android:footerDividersEnabled="false" 
     android:headerDividersEnabled="false" 
     android:layout_below="@+id/user_profile" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="false" 
     android:layout_alignParentTop="false" 
     android:layout_alignWithParentIfMissing="false" 
     android:layout_alignParentRight="false" 
     android:layout_alignParentBottom="false" /> 

YourActivity.java

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.list_view); 

    // inflate header to add to list view header 
    ListView listView = (ListView) findViewById(R.id.expandable_list); 
    listView.addHeaderView(getLayoutInflater().inflate(R.layout.user_profile, listView, false)); 

...add list adapter/other setup 
+0

이제 또 다른 문제. listview는 응용 프로그램 실행시 자동으로 목록의 아래로 스크롤합니다. 상단 (헤더)에 머무르게 만드는 방법 – dennes544

+2

android : transcriptMode = "normal"대신에 android : transcriptMode = "disabled"를 추가해보십시오. –

+0

네, 작동합니다, 고마워요! – dennes544

0

먼저 다른 스크롤 컨테이너 위젯 내에서 하나의 스크롤 컨테이너/위젯을 넣어 결코 -이 문제를 (내가 그것을 시도, 날 믿어 :))이 생성됩니다

지금까지 내가 문제가 당신이 스크롤 갖고 싶어 이해 그 위에 사용자 프로필 데이터가있는 목록?

나는 그런 식으로 어댑터 재정에

할 것

@Override 
public int getViewTypeCount() { 
    return MY_VIEW_TYPE_COUNTER //for example 2; 
} 

@Override 
public int getItemViewType(int position) { 
    if (position == 0) 
     return USER_PROFILE_TYPE_CONSTANT; 
    else 
     return NORMAL_LIST_ELEMENT_CONSTANT; 
} 

와의 getView 방법에서 그 이후

public View getView(int position, View convertView, ViewGroup parent) { 
    int type = getItemViewType(position); 
    if(type == USER_PROFILE_TYPE_CONSTANT) 
     /*inflate and set correct user profile view*/ 
    else 
     /* inflate and set "normal" list item*/ 
    return convertView 
} 

희망은 내가 문제를 이해 코 rectly :) 명확하지 않은 경우

+0

응답 해 주셔서 고맙지 만 사용자 프로필 데이터는 listview와 함께 스크롤해야합니다. 위로 스크롤하면 프로필 데이터도 위로 스크롤됩니다. – dennes544

+0

그런 다음 @TheRedBaron에서 제안한 솔루션처럼 들립니다. 사용자 프로필을 다른 XML에 넣으십시오. 파일, 프로그래밍 방식으로 프로그램에서/목록을 사용하여 조각을 inflate 및 headerview 같이 추가하십시오 - 스크롤 방법에 관계없이 목록 맨 위에 단순히 유지됩니다 :) – bartol

+0

thats 문제. 그것은 상단에 머물지 않아야한다. 목록보기 내용으로 화면을 스크롤해야한다. 내 코드를 따를 경우 – dennes544

1

ExpandableListView의 헤더로 확장하기 위해 ScrollView를 완전히 제거하고 별도의 레이아웃 파일에 'user_profile'RelativeLayout을 배치 할 수 있습니다. 이처럼 :

ExpandableListView listView = (ExpandableListView) findViewById(R.id.expandable_list); 
LayoutInflater inflater = getLayoutInflater(); 
ViewGroup header = (ViewGroup) inflater.inflate(R.layout.user_profile, listView, false); 
listView.addHeaderView(header);