I Have simple question, i Have some linear layout with buttons on it.
how can I make this linear layout share to all my application layouts without copy it to the beginning of each layout.
I mean that any xml layout will start from the same LinearLayout, and will share the same references , like browser bar but when I launch to another Activity it's still visible.
Thank's guys
Use the include tag in each of your layouts
<include android:id="#+id/layout_id" layout="#layout/my_layout" />
see this blog post http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/
Related
Here is my issue, I am working on the Ads integration for my Mobile Application.
In order to display a banner, I have created a BannerFragment.
I want to display this banner in all of my Activities, so that I have included it in a ActionBarAbstractActivity layout.
This allow me to display my Banner on all of my Activities without working on their XML files.
But, I have one specific Activity where I don't want to display Ads.
That's why I need to hide the Banner in this Activity. How can I access the BannerFragment in this Activity even if it's not referenced in its XML layout ?
I tried to find the Fragment by ID and hide it, but it's not working.
Should I create my proper banner container for this activty and set the visibility to "HIDE" or "GONE" ?
You can change the visibility property of the linear layout itself to hide/show the fragment.
Use an id for the LinearLayout in the XML.
<LinearLayout
android:id="#+id/bannerLayout"
android:layout_width="match_parent"
android:layout_height="50dp">
<fragment
..
..
/>
</LinearLayout>
In your activity,
LinearLayout bannerLayout = (LinearLayout) findViewById(R.id.bannerLayout);
To hide the layout,
bannerLayout.setVisibility(View.INVISIBLE); // Or in this case, View.GONE will also work
To show the layout,
bannerLayout.setVisibility(View.VISIBLE);
Maybe you can use include the xml of fragment instead of hide or gone.
like this
/>
I'm brand new to android development and I'm using both design view and text view to create a layout.
I've just used a scrollView element on the screen and have started to fill in all of the content. Unfortunately, the content is going off of the page (obviously will be scrollable when it's built). But I would like to be able to see the designed content before I run a build to see it.
Is there any way to expand my view of the scrollView element so I can see the content below the screen?
If you put all of the content you want in a separate layout using merge tag as the top level element you should be able to preview that layout in the preview window. Then just use an include tag to put it into the scrollView
eg
<merge xmlns:android="http://schemas.android.com/apk/res/android">
Your content here
</merge>
And
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/yourlayout"/>
</ScrollView>
See http://developer.android.com/training/improving-layouts/reusing-layouts.html
Well, obviously you can't scroll the screen in Android Studio, but you can set the visibility of any parent view to gone to see how your off-screen views look like, then change it back by removing the visibility attribute in xml.
You can also copy the views that are off-screen and paste them in another new layout for testing purposes only to see how it looks like.
Generally, you can just run the emulater in Android Studio and see how your design looks like too.
I'm dynamically adding views (RelativeLayout with EditText) into FrameLayout and setting their positions using setTranslate methods. But on screen keyboard overlaps on my EditText.
I've tried to set
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"
in manifest, but there is still no result. I'm using 11 SDK.
How to solve that problem?
Here is screeshots:
As you have already tried activity android:windowSoftInputMode in your Manifest. You can do it by chaging the Layout to relative and make your EditText android:layout_alignParentBottom="true"
Refer this Example
Surround your Relative layout with a <ScrollView>.
Place your view inside of this. ScrollView only accepts one child though, so you may need to add all of your components to a LinearLayout, then add the LinearLayout inside of the ScrollView.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ScrollView>
If that's not what you're looking for then add
android:layout_alignParentBottom="true"
The only thing that worked for me was putting an update in the manifest file within that specific activity tag which is hosting the fragment whose layout is creating the issue in scrolling. The solution is given by:
android:windowSoftInputMode="stateVisible|adjustPan"
Is there a way to make a button fix in the whole application views? I mean instead of adding the button to every xml file and code it.
Thank you.
You can keep your button xml code a different xml file. And to every other activity xml layout you can use the xml tag include like
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
<include layout="#layout/okcancelbar_button"/>
</LinearLayout>
Or like jack said, create a base activity that creates the buttons and the rest of the activities can extend from it.
you can create a custom activity in which you create one time button and every activity you will call, extended to your custom activity will have that button
On an iphone context, when we add a view as a subview of another view, anything that happens to our subview will be handled correctly, because in the xib we say which class will be handling its actions. How can we achieve this on android? Since we don't have that kind of relation between an .xml layout and a class that uses it, how can we achieve something like that?
The main purpose is, for example: while having one common header and one common footer for the entire application, we just want to add different views to "content View" between the header and footer.
You you can use the layout "include" functionality. This allows you to create a layout file for your header and one for your footer, and then include these layouts into your Activity's main layout. And if you want to include the header + footer in multiple activities and these layouts have some events you want to handle, you could create a BaseActivity that handles these events, and then have your other Activities extend the BaseActivity.
Example pseudocode:
title.xml
<LinearLayout><ImageView/><TextView/></LinearLayout>
footer.xml
<LinearLayout><TextView/><TextView/></LinearLayout>
main.xml
<RelativeLayout>
<include layout="#layout/title"/>
<WebView />
<include layout="#layout/footer"/>
</RelativeLayout>