Basically what I'm trying to do is have half the screen be a tab layout and half an image (or really anything else). It works just fine until I start adding weight.
As is, nothing is displayed. What would cause this problem?
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="left"
android:weightSum="2"
android:background="#00025a">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs">
</TabWidget>
<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#android:id/tabcontent">
</FrameLayout>
<FrameLayout
android:id="#+id/tabcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/test_room_1"/>
</android.support.v4.app.FragmentTabHost>
Without the weight component the tab related stuff displays, but I'm assuming it pushes the image out as it isn't shown.
Any help would be appreciated. :)
UPDATE:
Here's a screenshot as requested: Weighted
And the calling activity:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.widget.ImageView;
public class sandbox_mode extends FragmentActivity {
ImageView level_background;
private FragmentTabHost mTabHost;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sandbox_mode_play);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("Enemy Tab").setIndicator("Enemies"),
enemy_tab.class, null);
}
}
If you look at the documentation on FragmentTabHost link, you'll see that it's not inherited from LinearLayout, so basically layout_weight is not supported by this container. I would suggest adding additional top LinearLayout for this to work correctly.
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="left"
android:weightSum="2"
android:background="#00025a">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs">
</TabWidget>
<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#android:id/tabcontent">
</FrameLayout>
<FrameLayout
android:id="#+id/tabcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/test_room_1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
use childFragmentManager instead FragmentManager
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.tabcontent);
If you want to use nested fragments within a native Fragment. use getFragmentManager().
If you want to use nested fragments within a support library Fragment, use getChildFragmentManager().
Related
I have an image above my listview that is currently doing nothing.But I want my image to be animated when the user scrolls in the listview just like
this.
This is an example of an old library called StikkyHeader ,but it doesn't seem to work now.
Is there any other libraries for the same reason or even a way I can do it without libraries?
Try this one
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:minHeight="200dp"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:minHeight="150dp"
app:expandedTitleMarginBottom="25dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:layout_width="match_parent"
android:src="#drawable/magic_bg"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
android:layout_height="match_parent"/>
<TextView
android:layout_width="match_parent"
android:text="#KeepMakingMagic"
android:textSize="25dp"
android:gravity="center"
android:textColor="#color/white"
android:textStyle="bold"
app:layout_collapseMode="parallax"
android:layout_marginBottom="50dp"
android:layout_gravity="bottom"
app:layout_collapseParallaxMultiplier="-0.1"
android:layout_height="wrap_content"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<!-- You can have list view here Instead of scrollview But you need to make sure layout behaviour is same-->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#color/colorAccent"
android:layout_height="1000dp">
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Demo :
Don't forget to play with things
I followed the guidelines on the Google developer page to creat these 5 folders and filled them with icons of the correct dimensions:
I created my tabs using a TabHost like so:
TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("", getResources().getDrawable(R.drawable.homeicon));
TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
spec2.setContent(R.id.tab2);
spec2.setIndicator("", getResources().getDrawable(R.drawable.startachainwhite48dp));
TabHost.TabSpec spec3 = tabHost.newTabSpec("tab3");
spec3.setContent(R.id.tab3);
spec3.setIndicator("", getResources().getDrawable(R.drawable.joinachainwhite48dp));
TabHost.TabSpec spec4 = tabHost.newTabSpec("tab4");
spec4.setContent(R.id.tab4);
spec4.setIndicator("", getResources().getDrawable(R.drawable.viewchainswhite48dp));
TabHost.TabSpec spec5 = tabHost.newTabSpec("tab5");
spec5.setContent(R.id.tab5);
spec5.setIndicator("", getResources().getDrawable(R.drawable.profilewhite48dp));
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
tabHost.addTab(spec4);
tabHost.addTab(spec5);
But for some reason the icons on my tabs (at the bottom) show up tiny
Does anybody have an explanation/solution for this? I feel like I have made a silly mistake somewhere - will post xml layout if needed. Thanks in advance.
EDIT: It may be worth mentioning that the getDrawable() method I'm using in the above code is deprecated (API 22)
EDIT2: Full XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tool_bar_test"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF86B39A"
android:fitsSystemWindows="true"
android:gravity="top"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="Test"
android:textColor="#ffffff"
android:textSize="25sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.v4.widget.DrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sv_laptop03.myapp.Profile">
<TabHost
android:id="#+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"></RelativeLayout>
<RelativeLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
<RelativeLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"></RelativeLayout>
<RelativeLayout
android:id="#+id/tab4"
android:layout_width="match_parent"
android:layout_height="match_parent"></RelativeLayout>
<RelativeLayout
android:id="#+id/tab5"
android:layout_width="match_parent"
android:layout_height="match_parent"></RelativeLayout>
</FrameLayout>
</RelativeLayout>
</TabHost>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/headerview"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>
To make sure that every thing will looks as you expected, just add images into the xxxhdpi folder and be sure that they are 192x192 px.
By this method you let the OpenGL convert the image to what device the app is running on and that also give you the ability to resize your images without losing any details.
Hope this will help you.
Reference here:
https://developer.android.com/guide/practices/screens_support.html
I want use this library into my project : Library
My problem is how to enter the containerLayout, I got this code :
StikkyHeaderBuilder.stickTo(mListView)
.setHeader(R.id.header, containerLayout)
.minHeightHeader(250)
.build();`
my xml code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="230dp">
<ImageView
android:id="#+id/header_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/main_header" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="G Vision"
android:textSize="30sp"
android:textColor="#android:color/white"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
I saw a demo of the source, but the fragment used in the demo, and I want to use my activity.
How I should fill the container layer?
set id for the most outer RelaytiveLayout.
in your activity make object
RelativeLayout containerLayout = (RelaytiveLayout) findViewById(R.id.rel_id);
then put this in here
StikkyHeaderBuilder.stickTo(mListView)
.setHeader(R.id.header, containerLayout)
.minHeightHeader(250)
.build();
I have this xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<TextView
android:id="#+id/errorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/pointsText"
android:visibility="gone"/>
<TextView
android:id="#+id/pointsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/offers_list"
android:text="you have 100 points"
android:visibility="visible"/>
<ListView
android:id="#+id/offers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:dividerHeight="0dp"
android:divider="#00000000"/>
</RelativeLayout>
Yet I cannot see pointsText in my eclipse graphical previewer.
What am I missing?
You have
android:layout_above="#+id/offers_list"
for your TextView but you don't have any positioning for your ListView. Since RelativeLayouts place their children at the top-left by default, your ListView would be at the top and there would be nowhere above it to place your TextView.
Try removing that property from your TextView and add
android:layout_below="#id/pointsText"
on your ListView.
I just tested this and it does work. I can see the pointsText TextView above the list. So, you will want to do something different with your error TextView or you will quite possibly have the same issue with that when you want to change its visibility.
A bit off-topic
RelativeLayout doesn't have an orientation property so that doesn't do you any good but doesn't do you any real harm either.
When you use relative layouts, layout elements lay upon each other. To prevent that you should place element Relatively to other layouts. make your code like this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<TextView
android:id="#+id/errorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/pointsText"
android:visibility="gone"/>
<TextView
android:id="#+id/pointsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/offers_list"
android:text="you have 100 points"
android:visibility="visible"
android:layout_below="#+id/errorMsg"/>
<ListView
android:id="#+id/offers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:dividerHeight="0dp"
android:divider="#00000000"
android:layout_below="#+id/pointsText"/>
</RelativeLayout>
Now you will be able to see your all layouts
try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/errorMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="#+id/pointsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="you have 100 points"
android:visibility="visible"/>
</LinearLayout>
<ListView
android:id="#+id/offers_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/linearLayout1"
android:divider="#00000000"
android:dividerHeight="0dp"
android:drawSelectorOnTop="false" />
</RelativeLayout>
If this is a fragment inside an activity, you may want to check the nesting of say, the AppBarLayout and the layout into which you add the fragment
Im trying to show / hide a specifically ImageView, that it's inside a FrameLayout. At the same time, im gonna hide or show (on the contrary to ImageView), the LinearLayout with id recents_linear_layout
<com.android.systemui.recent.RecentsPanelView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recents_root"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:id="#+id/recents_bg_protect"
android:background="#drawable/status_bar_recents_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:clipToPadding="false"
android:clipChildren="false">
<com.android.systemui.recent.RecentsHorizontalScrollView android:id="#+id/recents_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/status_bar_recents_right_glow_margin"
android:divider="#null"
android:stackFromBottom="true"
android:fadingEdge="horizontal"
android:scrollbars="none"
android:fadingEdgeLength="#dimen/status_bar_recents_fading_edge_length"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/recents_linear_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
</LinearLayout>
</com.android.systemui.recent.RecentsHorizontalScrollView>
**<ImageView android:id="#+id/landscape"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0.0dip"
android:src="#drawable/landscape_img"
android:visibility="gone" />**
</FrameLayout>
<include layout="#layout/status_bar_no_recent_apps"
android:id="#+id/recents_no_apps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
</com.android.systemui.recent.RecentsPanelView>
My java code, throws a NullPointerException, because it cant find the ImageView (because this is being executed on com.android.systemui.recent.RecentsHorizontalScrollView. This is the code
mLinearLayout = (LinearLayout) findViewById(R.id.recents_linear_layout);
mLinearLayout.setVisibility(mRecent ? LinearLayout.GONE : LinearLayout.VISIBLE);
mLandScape = (ImageView) findViewById(R.id.landscape);
mLandScape.setVisibility(mRecent ? View.VISIBLE : View.GONE);
Thanks in advance.
you could use ((Activity)getContext()).findViewById(R.id.landscape) though you should avoid it since there is no guarantee that the context is an activity. I can't understand why you are trying to hide some views inside this view. I think this is the activity's responsibility. You should make some interface with call back method to notify the activity about your event then let it hide the image view.
FIXED
Fix was making a external layout container with old Layout and ImageView as childs
<com.android.systemui.recent.RecentsHorizontalScrollView android:id="#+id/recents_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/status_bar_recents_right_glow_margin"
android:divider="#null"
android:stackFromBottom="true"
android:fadingEdge="horizontal"
android:scrollbars="none"
android:fadingEdgeLength="#dimen/status_bar_recents_fading_edge_length"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/child_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/recents_linear_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false" />
<ImageView android:id="#+id/sense_landscape"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0.0dip"
android:src="#drawable/sense_landscape"
android:visibility="visible" />
</LinearLayout>
</com.android.systemui.recent.RecentsHorizontalScrollView>