1

I am about to finish developing an Android application, but I am having difficulties in rendering the profile Fragment Layout. Basically what I have done so far is that I placed the information of the user at the top of a LinearLayout and in the bottom I have a list View with all the messages that he/she have posted so far. By doing so I am not able to scroll the LinearLayout when the ListView is been scrolled.

What I want to do is scroll the LinearLayout with all the user information, when someone scrolls the ListView (Like Facebook Profile Page).

Here is the existing XML:**

<LinearLayout>
    <LinearLayout>
        <!-- User information. -->
    </LinearLayout>

    <ListView/>

</LinearLayout>
MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
whit3hawks
  • 429
  • 7
  • 14
  • You can make the first item in the list view a different layout than the rest and fill it with the user info. See [this](http://stackoverflow.com/questions/4777272/android-listview-with-different-layout-for-each-row) for how to do that. – mpkuth Dec 15 '14 at 04:57
  • 2
    Try to add user information in ListView header layout. – Haresh Chhelana Dec 15 '14 at 04:57

3 Answers3

1

Use custom listview

public class CustomExpandableListView extends ListView {

ListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

ListView(Context context) {
    super(context);
}

public ListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    // Calculate entire height by providing a very large height hint.
    // View.MEASURED_SIZE_MASK represents the largest height possible.
    int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
            MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, expandSpec);

    ViewGroup.LayoutParams params = getLayoutParams();
    params.height = getMeasuredHeight();
}
}

replace your

 <ListView/> 

with

<com.wsc.common_methods.ListView/>

and put your overall layout within scrollview

Ravi Sharma
  • 753
  • 1
  • 7
  • 13
0

Define two layout for Showing user info and messages like one layout contain ListView And another layout contain user information views,In activity load ListView Layout and add user information layout to ListView header.

user_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</LinearLayout>

user_header.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/txtUserName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

User Activity

private ListView listView;
private TextView txtUserName;
private View header;

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

    listView = (ListView) findViewById(R.id.listView);
    header = LayoutInflater.from(this).inflate(R.layout.user_header,null);
    txtUserName= (TextView) header.findViewById(R.id.txtUserName);

    listView.addHeaderView(header);
}
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
0

For this you have to put your hole view inside ScrollView.Your Xml parent layout should be Scroll View.For proper scrolling of your list view inside scroll view you have to use ExpandableHeight Listview.

Please see link1 - enter link description here

link2 - enter link description here

Hope it will solve your problem.

Community
  • 1
  • 1
Ravi Bhandari
  • 4,682
  • 8
  • 40
  • 68