Im using Caldroid library. I want to use it inside my layout. My layout also includes textview. But when I use Caldroid with framelayout the other views disappear.
Here is XML and Java codes using Caldroid with FrameLayout.
<LinearLayout 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="com.birfincankafein.mpandroidchart.CalendarFragment"
android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/container_caldroid"
android:layout_weight="0.4">
</FrameLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/imageView_divider"
android:layout_below="#+id/container_caldroid"
android:focusableInTouchMode="false"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="0.1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageView_divider"
android:background="#ffff00ba"
android:layout_weight="0.4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView_description"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ff00ebff"/>
</RelativeLayout>
Here is java code:
mCaldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
args.putInt( CaldroidFragment.START_DAY_OF_WEEK, CaldroidFragment.MONDAY );
mCaldroidFragment.setArguments( args );
getActivity().getSupportFragmentManager().beginTransaction().replace( R.id.container_calendar , mCaldroidFragment ).commit();
And here what it looks like:
These are codes for using Caldroid with fragment.
<LinearLayout 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="com.birfincankafein.mpandroidchart.CalendarFragment"
android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
class="com.roomorama.caldroid.CaldroidFragment"
android:id="#+id/container_caldroid"
android:layout_weight="0.4">
</fragment>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/imageView_divider"
android:layout_below="#+id/container_caldroid"
android:focusableInTouchMode="false"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="0.1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageView_divider"
android:background="#ffff00ba"
android:layout_weight="0.4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView_description"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ff00ebff"/>
</RelativeLayout>
And there is no need to java code. It had been initialized. Here is how it looks:
Why this happens? I want to use this library inside the frame layout. Because I have to initialize it manually. I have to set something neccassary.
Ps: The background color is for detect where the layout is.
I'm not able to recreate the same. The below code works fine for me.
XML:
<?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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/cal_container"
android:layout_weight="0.4"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/imageView_divider"
android:layout_below="#+id/container_caldroid"
android:focusableInTouchMode="false"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="0.1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageView_divider"
android:background="#ffff00ba"
android:layout_weight="0.4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView_description"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ff00ebff"/>
</RelativeLayout>
</LinearLayout>
Fragment:
public class meets extends Fragment {
public meets() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_meets, container, false);
CaldroidFragment mCaldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
args.putInt( CaldroidFragment.START_DAY_OF_WEEK, CaldroidFragment.MONDAY );
mCaldroidFragment.setArguments( args );
getActivity().getSupportFragmentManager().beginTransaction().replace( R.id.cal_container , mCaldroidFragment ).commit();
return root;
}
}
Related
I am trying to set my custom dialog fragment to use the full width of the screen. The one solution is to set LayoutParams on view. But they are not working.
Things I Tried
Changing parent Layout
using getLayoutParams().getClass() which returns null
Layout Validator shows correct layout so no prob here, here is my Layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
style="#style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked"
android:id="#+id/ask_hint_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="#+id/puppy_vw"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<pl.droidsonroids.gif.GifImageView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:src="#drawable/solving"
android:adjustViewBounds="true">
</pl.droidsonroids.gif.GifImageView>
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked"
android:text="#string/ad_confirm_text"/>
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_below="#id/puppy_vw"
android:id="#+id/ad_confm_btns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_centerInParent="true">
<com.google.android.material.button.MaterialButton
android:id="#+id/yes_hint"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:text="Yes">
</com.google.android.material.button.MaterialButton>
<!--
<com.google.android.material.button.MaterialButton
android:id="#+id/no_hint"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:text="No">
</com.google.android.material.button.MaterialButton>
-->
<com.google.android.material.button.MaterialButton
android:id="#+id/why_hint"
android:layout_margin="5dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
android:text="Why Ads?">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
Here is my DialogFragment class
public class AdLoadFragment extends DialogFragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
AskHintDialogBinding binding=AskHintDialogBinding.inflate(inflater,container,false);
View view=binding.getRoot();
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MyUtilsApp.showLog(String.valueOf(view.getClass()));
view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
}
}
The problem I am having is getting a listview to work inside my fragment. I have tried creating a custom adapter but then I don't have anything appear on my screen, perhaps I am not doing it right.
My main xml for fragment looks like this:
<ListView
android:id="#+id/pieChartView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
/>
The adapter layout looks like this:
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="2dp"
/>
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart2"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="2dp"
/>
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart3"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="2dp"
/>
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart4"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="2dp"
/>
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart5"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="2dp"
/>
The fragment code :
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_piechart, container, false);
Log.i(ACTIVITY_NAME, "In onCreate()");
chart1 = root.findViewById(R.id.chart1);
chart2 = root.findViewById(R.id.chart2);
chart3 = root.findViewById(R.id.chart3);
chart4 = root.findViewById(R.id.chart4);
chart5 = root.findViewById(R.id.chart5);
ChartOne();
ChartTwo();
return root;
}
The problem I am having is creating a custom adapter inside the fragment. I tried one and then with my code above I got an error with where I create the charts(ChartOne,ChartTwo).
This is representation of my app layout:
Where should I create onClickListeners for included layouts? I tried inside the fragment but I could not get through with findViewById. So I tried from Main Activity but I'm not sure how to get to included layouts from there.
I also tried this inside the fragment:
public class MainMenu extends Fragment implements View.OnClickListener{
View button_call;
#Override
public View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedinstanceState) {
View myView = inflater.inflate(R.layout.fragment_main_menu, container, false);
button_call = myView.findViewById(R.id.btn_call);
button_call.setOnClickListener(this);
return myView;
}
#Override
public void onClick(View v) {
// implements your things
}
public MainMenu() {
}
}
But then Fragment seems to be empty
Fragment XML:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/mainmenu_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="60dp">
<include android:id="#+id/btn_call"
layout="#layout/call_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:paddingBottom="30dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"/>
<include android:id="#+id/button2"
layout="#layout/message_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:paddingBottom="30dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<include android:id="#+id/button3"
layout="#layout/navigate_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:paddingBottom="30dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"/>
<include android:id="#+id/button4"
layout="#layout/remind_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:paddingBottom="30dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"/>
</LinearLayout>
</ScrollView>
Steps
Create a xml file you want to inclue (eg. web.xml)
use include tag in fragment's xml and connect your layout you need to include using layout="#layout/
Initialize include tag inside fragment (when you do this make sure about the root tag of your web.xml)
Once initializing include tag is done access views inside the layout that included (web.xml) using include tag
Example
Here in my fragment I have an include tag in it's XML. It connects to my web.xml and ..web.xml's parent tag/ root tag is a FrameLayout ..
Now see how I initialize my include tag..(If you do not use the right root tag to initialize include,it will crash with a null pointer)
I have an id called g_betta in my web.xml( XML layout that I included in my fragment)
see how I access that view..
public class FragmentAbout extends Fragment {
private RelativeLayout relativeLayoutConnectedInsideIncludeTag;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_fragment,container,false);
FrameLayout view =(FrameLayout) rootView.findViewById(R.id.include_tag);
relativeLayoutConnectedInsideIncludeTag = (RelativeLayout) view.findViewById(R.id.g_betta);
relativeLayoutConnectedInsideIncludeTag.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Yes I Found you", Toast.LENGTH_SHORT).show();
}
});
return rootView;
}
}
my fragment xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/mainmenu_layout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
<include
android:id="#+id/include_tag"
layout="#layout/web"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
my include--> web.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/maroon"
android:gravity="center_horizontal">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/g_betta"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="HELLO"
android:textColor="#FFF"
android:textSize="20dp" />
<RelativeLayout
android:id="#+id/lin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="16dp"
android:background="#color/colorPrimaryDark"
android:gravity="bottom"
android:paddingLeft="24dp"
android:paddingRight="24dp" />
</RelativeLayout>
<ImageView
android:id="#+id/imageone"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/lin"
android:layout_margin="16dp"
android:background="#drawable/girl"
android:scaleType="fitXY" />
<ImageView
android:id="#+id/imagetwo"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/imageone"
android:layout_margin="16dp"
android:background="#drawable/amanda"
android:scaleType="fitXY" />
</RelativeLayout>
</ScrollView>
</FrameLayout>
Do like this:
button_call = myView.findViewById(R.id.btn_call);
button_call.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// write your code here...
});
I´d like to design a layout in XML and want to duplicate it dynamicly, depence on the size of a list. It has to be done in a fragment. Unfortunally I cannot find how to do it in fragments.
This ist the idea of the XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<FrameLayout
android:id="#+id/complete_map_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ICH bin die MAP!! Ich möchte ein Bild werden"
android:id="#+id/textView7"
android:layout_gravity="center_horizontal" />
<!-- Erstellung einzelner Räume -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="20dp"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:id="#+id/roomRow">
<!-- Bezeichnung Raum -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.10"
android:orientation="vertical"
android:id="#+id/roomNameOne"
android:background="#ff0000">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/roomName"
android:layout_gravity="center_vertical"
android:rotation="-90"
android:text="PLATZHALTER"/>
</LinearLayout>
<!-- Inhalt Raum -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:orientation="horizontal"
android:id="#+id/WeaponNameOne">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/testWeapon"
android:layout_gravity="center_vertical"
android:text="WAFFE"
android:background="#00ff00"/>
</LinearLayout>
<!-- Inhalt Raum2 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:orientation="horizontal"
android:id="#+id/weaponNameTwo"
android:background="#0000ff">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/testWeapon2"
android:layout_gravity="center_vertical"
android:text="WAFFE"/>
</LinearLayout>
<!-- Bezeichnung Raum2 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.10"
android:rotation="90"
android:id="#+id/roomNameTwo"
android:background="#ff0000">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/roomName2"
android:layout_gravity="center_vertical"
android:text="PLATZHALTER"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_gravity="right|bottom" />
</FrameLayout>
</ScrollView>
This is the java-code:
public class MapOverview extends Fragment {
Bundle extras;
View fragLayoutV;
Game game;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragLayoutV = inflater.inflate(R.layout.fragment_map, null);
extras = getActivity().getIntent().getExtras();
game = (Game) extras.get("GAME");
return fragLayoutV;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FrameLayout frame = (FrameLayout)fragLayoutV.findViewById(R.id.complete_map_layout);
//LinearLayout roomInflator = (LinearLayout)frame.findViewById(R.id.roomRow);
Log.e("RAUM", game.getRooms().get(0).getName());
for(Room r:game.getRooms()){
frame.addView((LinearLayout)frame.findViewById(R.id.roomRow));
}
}
}
Of course I get an error by doing this. Can anybody help?
The aim is to have a picture like this:
http://i.stack.imgur.com/3DS73.png
Don´t matter about the colors ^^
You need to re-inflate your layout every time you want to add it. You can not add the same View multiple times.
Try something like this:
LayoutInflater inflater = LayoutInflater.from(this.getContext());
for (Room r : game.getRooms()) {
View view = inflater.inflate(R.layout.your_duplicate_layout, frame, false);
// Do whatever you want with view
frame.addView(view);
}
Where R.layout.your_duplicate_layout correspond to your current layout with id=roomRow.
With the layout below the buttons are being shown on top of the page. How can I make them appear below, after the container, down on the page?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/container"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/Main"
android:onClick="ClickHomePage"
android:text= "#string/Home"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/map"
android:onClick="ClickClients"
android:text= "#string/Clients"
>
</Button>
</LinearLayout>
</LinearLayout>
The MainActivity looks as follows and the HomePage.xml is also below
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GetButtonClicked(5);
setContentView(R.layout.activity_main);
}
public void GetButtonClicked(int position)
{
// update the main content by replacing fragments
Fragment fragment = null;
switch (position){
case 0:
fragment= new FirstPageFragment();
break;
default:
fragment = new FirstPageFragment();
break;
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
public void ClickHomePage(View view){
GetButtonClicked(0);
}
public void ClickClients(View view){
GetButtonClicked();
}
}
<FrameLayout 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="com.test.FirstPageFragment" android:background="#drawable/theme">
</FrameLayout>
This is the FirstPage
public class FirstPageFragment extends Fragment {
public FirstPageFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first_page, container, false);
}
}
Use ralative layout insted of linear.
Make a different layout for bottom buttons, and then at the last of your container layout use this:
<include android:id="#+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
layout="#layout/bottom_buttons"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="#+id/Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickHomePage"
android:text="#string/Home" />
<Button
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickClients"
android:text="#string/Clients" >
</Button>
</LinearLayout>
Try this
Use RelativeLayout with android:layout_alignParentBottom="true" step by step guide is available here.
Your skeleton for layout should look like this
<RelativeLayout
<LinearLayout android:layout_alignParentBottom="true">
<Button
<Button
</LinearLayout>
</RelativeLayout>
Final Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickHomePage"
android:text="Home" />
<Button
android:layout_marginLeft="30dp"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickClients"
android:text="Clients" >
</Button>
</LinearLayout>
The issue was that I did not include the container in another layout...
<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="com.test.MainPageActivityActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="#+id/container">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentTop="#+id/container">
and insert buttons layout here....
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/Main"
android:onClick="ClickHomePage"
android:text= "#string/Home"
/>