I’m trying to make a file manager application where I list the contents of a certain directory in a ListFragment in the upper half of the screen(needless to say this list could be scrollable) and when a user taps on a certain file/folder, the meta-data associated with it should be visible in a FrameLayout placed right below the fragment, along with a thumbnail image of the file type. Here’s my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<fragment
android:id="@+id/titles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.test.fileManager.FileManagerActivity$TitlesFragment"
/>
</ScrollView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:background="#00000000"
>
</FrameLayout>
</LinearLayout>
I used ‘layout_weight’ property first without the ScrollView tags, but those weight properties are just not respected by the fragment and the list extends well upto the bottom of the screen.
When I enclose the fragment in ScrollView tags(I know..not a good idea!), I only see one entry of the list at a time.
Is there anyway in which I can have the ListFragment occupy the top 40% of the screen and display a scrollable list in that 40% screen space, when necessary?
First, get rid of the
ScrollView. IfTitlesFragmentis aListFragment, you cannot reliably put aListView(from theListFragment) in aScrollView.Next, set the height of the fragment to be
0px. You cannot reliably usematch_contentas the height of aListView.Then, to do things purely by percentage, also set the height of your
FrameLayoutto0px, then assign your weights as you wish (e.g., 40 for the fragment and 60 in theFrameLayout).