0

I have a problem in building a XML layout with a videoView of half of the screen, a expandableList with two children and some textView below the video frame. The text is below the list, so if I expand the list and the list fill the rest of the half screen, it should be able to scroll to the textView.

My idea was to put the expandableList inside a scrollView, but I was not able to expand the list.

I built my layout as follows:

  • LinearLayout
    • VideoView
    • ScrollView
      • LinearLayout
        • ExpandableListView
        • TextView>
        • ...

Is there an alternative way to realize my intention or why can't I expand my List.

Edit: XML Layout:

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

<VideoView
    android:id="@+id/video_player_h"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1" >

    <ExpandableListView
        android:id="@+id/expandableList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:groupIndicator="@drawable/group_indicator" >

        <TextView
            android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Empty" >
        </TextView>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/view_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:text="Views: "
                android:textSize="16sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/view_text"
                android:gravity="center"
                android:hint="12345"
                android:paddingLeft="10dp"
                android:textSize="16sp" />

            <RatingBar
                style="@style/newRatingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:isIndicator="false"
                android:numStars="5"
                android:rating="3" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/date_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:paddingLeft="10dp"
                android:text="Date: "
                android:textSize="16sp" />

            <TextView
                android:id="@+id/date_video"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/date_text"
                android:hint="11.11.1111"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/uploader"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:hint="Mr. X"
                android:paddingRight="10dp"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/user_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@id/uploader"
                android:text="User: "
                android:textSize="16sp" />
        </RelativeLayout>
    </ExpandableListView>
</ScrollView>

</LinearLayout>

Class:

public class Player extends Activity {
ExpandableListView titleList;
VideoView videoView;
ExpandableListAdapter exp;

private static final String OUTPUT_FILE="/storage/sdcard0/bigbuckbunny.3gp";

public int GetDipsFromPixel(float pixels)
{
 float scale = getResources().getDisplayMetrics().density;
 return (int) (pixels * scale + 0.5f);
}


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

    videoView = (VideoView) findViewById(R.id.video_player_h);
    MediaController mc = new MediaController(this);
    videoView.setMediaController(mc);
    videoView.setVideoPath(OUTPUT_FILE);

    if (getResources().getConfiguration().orientation == 1) {
        titleList = (ExpandableListView) findViewById(R.id.expandableList);

        ArrayList<String> groupList = new ArrayList<String>();
        groupList.add("Titel");
        ArrayList<ArrayList<String>> childrenList = new ArrayList<ArrayList<String>>();
        ArrayList<String> childrenElement = new ArrayList<String>();
        childrenElement.add("Beschreibung");
        childrenList.add(childrenElement);
        ExpandableListAdapter listAdapter = new ExpandableAdapter(this, groupList, childrenList);

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int width = metrics.widthPixels;

        titleList.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10));
        titleList.setAdapter(listAdapter);
        titleList.setDividerHeight(1);
        titleList.setClickable(false);

    }

}

class ExpandableAdapter implements ExpandableListAdapter {

    Context context;
    ArrayList<String> groups;
    ArrayList<ArrayList<String>> children;

    public ExpandableAdapter(Context context, ArrayList<String> groups, ArrayList<ArrayList<String>> children) {
        this.context = context;
        this.groups = groups;
        this.children = children;
    }


    public Object getChild(int groupPosition, int childPosition) {
        return children.get(groupPosition).get(childPosition);
    }

    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        if(convertView==null){
            LayoutInflater inflator = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView  = inflator.inflate(R.layout.title_child, null);
        }
        TextView text = (TextView) convertView.findViewById(R.id.child_field);
        text.setText(children.get(groupPosition).get(childPosition));
        return convertView;
    }

    public int getChildrenCount(int groupPosition) {
        return children.get(groupPosition).size();
    }

    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    public int getGroupCount() {
         return groups.size();
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if(convertView==null){  
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.title_group, null);
        }
        TextView text = (TextView) convertView.findViewById(R.id.group_field);
        text.setText(groups.get(groupPosition));
        return convertView;
    }

    public boolean hasStableIds() {
        return true;
    }

    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    public boolean areAllItemsEnabled() {
        return false;
    }

    public long getCombinedChildId(long groupId, long childId) {
        return 0;
    }

    public long getCombinedGroupId(long groupId) {
        return 0;
    }

    public boolean isEmpty() {
        return false;
    }

    public void onGroupCollapsed(int groupPosition) {
    }

    public void onGroupExpanded(int groupPosition) {
    }

    public void registerDataSetObserver(DataSetObserver observer) {
    }

    public void unregisterDataSetObserver(DataSetObserver observer) {
    }

}
}
LikeMusic
  • 55
  • 1
  • 5

1 Answers1

0

Of course, what I suggest is

  • Scroll View

    • Expandable list
      • Text view 1
      • Text view 2
      • So on...

    <ExpandableListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:groupIndicator="@drawable/group_indicator">
    
        <TextView 
            android:id="@+id/android:empty" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:text="Empty">      
        </TextView>
    
    
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        <TextView
            android:id="@+id/view_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:text="Views: "
            android:textSize="16sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/view_text"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:hint="12345"
            android:textSize="16sp" />
    
    </RelativeLayout>
    
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        <TextView
            android:id="@+id/date_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:paddingLeft="10dp"
            android:text="Date: "
            android:textSize="16sp" />
    
        <TextView
            android:id="@+id/date_video"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/date_text"
            android:hint="11.11.1111"
            android:textSize="16sp" />
     </RelativeLayout>
    </ExpandableListView>
    </ScrollView>
    
adarsh
  • 6,738
  • 4
  • 30
  • 52
  • This causes an exception: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView – LikeMusic Dec 11 '12 at 11:23
  • You may have to make the appropriate change in your code for adding the view in your code. Are you initialising correctly after change? – adarsh Dec 11 '12 at 11:48
  • I tried to appropriate but I couldn't solve the problem. I edited my post with the entire code. Can you expand your suggestion? – LikeMusic Dec 11 '12 at 12:31
  • http://stackoverflow.com/questions/11154379/java-lang-unsupportedoperationexception-addviewview-layoutparams-is-not-supp See this thread. Make one expandable view and then add the rest of the stuff through code into the expandable view as you are doing? – adarsh Dec 11 '12 at 13:03