Android Fragment Tabbar - Invisible on Main Page? - android

I have a custom tabbar on the bottom of my android view.
I would like to have it "GONE" on the mainpage, because the main page content should take the entire height available.
But it seems to me, that even when I set visibility="gone" the 100dp height of the tabbar is still taken into account when rendering the mainpage, as the content view is not of full height.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:gravity="center_horizontal">
<FrameLayout android:layout_width='fill_parent'
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" android:id="#+id/content">
</FrameLayout>
<fragment android:name="MainActivity$TabBarFragment"
android:visibility="gone"
android:id="#+id/tabbar"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="100dp"/>
How can I get the ContentView to take full height at the mainpage?

Found it by myself.
I am now using:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:gravity="center_horizontal">
<FrameLayout android:layout_width='fill_parent'
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" android:id="#+id/content">
</FrameLayout>
<fragment android:name="MainActivity$TabBarFragment"
android:id="#+id/tabbar"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
and instead the TabBarFragment Layout File defines it's height and defines visibility=gone.
That works.

Related

Android LinearLayout with Button and FrameLayout using the Maximum Height

I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>

Two fragments in one layout but only one is shown

I am working on an android project and I am trying to make use of fragments but I am having an issue.
In my fragment activity I have a layout which contains two fragments. For some reason when I load the activity, I am only seeing the first fragment which is the query editor.
Below is the layout for the fragment activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_width="fill_parent"
android:layout_height="300dp" />
</LinearLayout>
</RelativeLayout>
Below is the layout for the query editor fragment
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#c1c1c1c1" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="QUERY EDITOR"/>
</LinearLayout>
Below is the layout for the result view fragment
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="RESULT SET VIEW"/>
</LinearLayout>
For some reason only the query editor is being shown.
Although at the moment the query editor is set to 100dp and the result view is 300 dp I am only doing this as a test.
What I am actually wanting to do is to the query editor set to 100dp and the result view take up the rest of the space.
Thanks for any help you can provide
Change
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_width="fill_parent"
android:layout_height="300dp" />
with
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="300dp" />
this way your fragments will occupy the same space in the LinearLayout
Why do you have a LinearLayout inside a RelativeLayout?
This should do the thing:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_below="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="300dp" />
</RelativeLayout>

How to show other views after list view height set to fill_parent

To prevent multiple GetView calling I have set the height of ListView to fill_parent.
How to show other views than the ListView itself?
The following layout is inflated in a ViewPager:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
where the included layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp" >
<ScrollView
android:id="#+id/prontuariohome_scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none" >
.
.
.
.
</ScrollView>
</LinearLayout>
EDIT: This solution won't work for view higher than a button
I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
Try to use following code
android:layout_height="0dp"
android:layout_weight="1"
in ListView tag
With android:layout_height="0dip" the view will take the rest of the free place
You said this solution is wont work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" android:layout_above="#+id/bt"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bt" android:layout_alignParentBottom="true"/>
just add it a android:layout_above="#+id/bt" to listview.
I'm sorry for being not clear.
Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.
After some tries I'm happy to give you the solution of my problem.
Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>

change the width of linear layout in android

I am having this xml layout for a list view :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/menu"
android:orientation="vertical" android:background="#2f4f4f" android:layout_width="wrap_content" android:layout_height="fill_parent">
<ListView android:id="#+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#2f4f4f" android:cacheColorHint="#2f4f4f" android:scrollbars="none">
</ListView>
</LinearLayout>
The linear layout occupies the full screen width by default.
I want to change it programatically.I want to make something like this :
But when I change width of linearlayout nothing happens,it still occupies full screen width
LayoutInflater inflater = LayoutInflater.from(this);
View menu = inflater.inflate(R.layout.xml_layout, null);
menu.setLayoutParams(new LayoutParams(20,LayoutParams.WRAP_CONTENT));
after hardcoding layout width in list view as :
<ListView
android:id="#+id/list"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#2f4f4f"
android:cacheColorHint="#2f4f4f"
android:scrollbars="none" >
</ListView>
I get this :
Please suggest a way to do this.
make changes in listview like shown below, do hard code for layout width in XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#android:color/white">
<ListView
android:id="#+id/list"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#2f4f4f" >
</ListView>
</LinearLayout>
you were doing Wrap_content in linear layout and in listview fill_parent, therefore linearlayout which is wrapping listview i.e. full screen.
If you'd like it to fit multiple screen sizes I'd suggest adding an empty layout and using weights.
Like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" android:background="#android:color/white">
<ListView
android:id="#+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="#2f4f4f" >
</ListView>
<LinearLayout android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" android:background="#android:color/white">
</LinearLayout>
I just eyeballed the weights. Adjust them to the width that you need. If you do it this way then you won't have to hard code the size for every screen size.

Android Layout Listview height adjustment under relativelayout

I would like add a listview or tableview occupy 2/3 of the screen and then there would a giant button at the center just beneath the listview. Right now the problem is the listview take up the whole height of the screen. I couldn't adjust the height on the graphical layout. I would like to take up only 5 Items height size. Beneath would be button center on screen,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/relativeLayout"
android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_height="wrap_content"
android:id="#+id/listView1"
android:layout_width="fill_parent" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"></ListView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/relativeLayout"
android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_height="fill_parent"
android:id="#+id/listView1"
android:layout_above="#+id/button1"
android:layout_width="fill_parent"></ListView>
<Button android:layout_height="wrap_content"
android:id="#+id/button1"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"></Button >
</RelativeLayout>
From what you said in your question, it sounds like a vertical LinearLayout would work better for you.
That way you could have the ListView take up exactly two thirds of the screen by placing two views inside the top level LinearLayout, and use weights to distribute the views on the screen.
For example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</LinearLayout>

Categories

Resources