How can i include a preference.xml in a fragment that is in a tab?
All i want is the layout i have my own logic for settings, i just want the standard preferencescreen look.
This is my latest attempt.
<include layout="#xml/preferences"
android:id="#+id/rtes"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
</include>
I thought this would be easier then to copy the look with a standart layout ...
android doesnt like to include layouts from the xml folder into layouts from the layoutfolder , i still think this should be possible but i couldnt find a way.
If anyone ses this question use this https://stackoverflow.com/a/30334930/6752994 and fake it... dumb i know ...
Related
I am, at the moment, trying to make a google maps app using android studio.
Right now, everything is fine, except for one thing, when i go to the "Design" Tab, in the XML file i have this Redering message:
Rendering Problems A tag allows a layout file to
dynamically include different layouts at runtime. At layout editing
time the specific layout to be used is not known. You can choose which
layout you would like previewed while editing the layout...
And the main problem is that I cannot use any of the gui components in my layout, I searched about my problem and i understood that with this error, people couldn't see their map but they could put on textfields, widgets, layouts, etc.
But for me, my preview is completly frozen and i can't do any modification.
Picture of my android studio page.
As you can change the fragments dynamically with your code, android studio doesn't know which layout to show in design time. This is the reason of your error.
To specifically tell android which layout to show, add tools:layout="#layout/Your_layout_name" attribute to your fragment.
There is also a shortcut link below the error description which you have told. Just click on the link and android will add it for you and you will see the fragment in your layout with no rendering error messages.
For a detailed example:
<?xml version="1.0" encoding="utf-8"?>
<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.example.insane.fragmenttest.MainActivity">
<fragment
android:id="#+id/testFragmentID"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.insane.fragmenttest.WorkOutDetails"
tools:layout="#layout/fragment_work_out_details" /> <!-- This is the line you want to add. -->
</LinearLayout>
Try using Designtime Layout Attributes. http://tools.android.com/tips/layout-designtime-attributes
These attributes guide Android Studio on how to render run-time attributes in the layout editor.
I think you should include tools:showIn="#layout/activity_maps" in your the <fragment> part of your google_maps_api.xml
Just use this design for the fragment. This solved my problem. Also, refer to this link
<fragment
android:id = "#+id/ma"
android:name = "com.google.android.gms.maps.SupportMapFragment"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = "com.example.demomaps.MapsActivity"
/>
Yes I solved this easily..Simply ignore the message and click line that is showing below of the rendering messages.
Actually fragment contains layout inner and if its not include its showing warning that it must contains you can simply ignore this message below the warning then this rendering issue will be resolved.
If I have three different layouts for a same view (lets say, one for phone, one for tablet and one for tablet in landscape) and I want to add/change a property that the three of them share (lets say, the android:background), is there a way of adding/changing it in one place and have it automatically in the other two layouts? Is there an alternative to copy-and-paste it?
Unfortunately not really. You could have separate layouts for each set of elements and use include to include them in each subsequent layout, then just updating the single layout would update all of them. But this would mean having a lot of stand alone layouts. A good example of this is using a seperate Toolbar layout like so:
Toolbar layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
style="#style/Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
Then have this line in all layouts which you want to use Toolbar.
<include layout="#layout/toolbar" />
This technique could be applied to anything you like, and would allow you to in future only edit each separate layout once and have it applied everywhere you use it. You can also edit dimensions inside these Layouts under the include, or in code.
The only other way to achieve what you want would be to handle it all explicitly in code but I wouldn't recommend this.
You can apply style for the widget(TextView or LinearLayout for example) that uses background property and determine background property in that style.
Changing background property in style will affect all the widgets this style was previously applied to.
http://developer.android.com/guide/topics/ui/themes.html
I am using my app currently ,made of fragments , just on phone. I am planning to add tablet version of the same , but seems like some fragments don't work exactly as expected on the tablet and often many mess up on landscape.So I just needed some pointers how to go about the same?
Here is my code for one of the fragments layout in 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="wrap_content"
android:background="#color/altercolor2" >
<HorizontalPageView
android:id="#+id/headline_gallery"
android:layout_width="match_parent"
android:layout_height="140dp" />
<include layout="#layout/loading_no_results" />
</FrameLayout>
How do I alter it such that the height even works on tablet as expected without cutting off some data? Also, should i add another duplicate layout somewhere for this or there's way around it? Any help appreciated,thanks!
Try this. Make a new layout-xlarge folder in /res directory and place all your tablet related xml files in that folder. Android system automatically fetches layout files from this layout-xlarge folder for 7-10 inch screens.
And to support landscape mode, design your layout files specifically for landscape mode and put it in layout-land folder. But make sure that the name of the files in all the folders are same.
Android Training guide covers this best.
You should read it
http://developer.android.com/guide/practices/screens_support.html#support
Theory, logic and best practices are a bit long to be explained here. So, my suggestion is to read this tutorial from the official documentation, http://developer.android.com/training/basics/fragments/index.html, checking all the topics and the links suggested by Google.
Also check the example application provided by them as well.
Having done that, if you have a more specific issue, please ask here and we will be more than happy to help you.
Try putting your main views i.e HorizontalPageView in a linear layout and make use of the weight and orientation attributes of the linear layout.
As I understand from your code you want to align the views vertically, in this case the "weight" attribute does wonders
first you need to figure out whether you will use a different ui for tablet version besides the phone version, if you use the same ui disign, (one pane or two panes), just thinking about portrait/landscape is enough, otherwise you need use style and value-swxxx to arrange the layout files for tablet and phone.
Besides the phone/tablet issue, you also need use layout-land to define the same layout unit for the landscape mode. so there are (phone-portrait, phone-landscape, tablet-portrait, tablet-landscape) four scenarios.
I have a layout menu which contains this:
<RelativeLayout android:id="#+id/computersMenu"
android:layout_width="50dp"
android:layout_height="50dp">
<include layout="#layout/component_add_button"
android:id="#+id/imagebutton_add_client"/>
</RelativeLayout>
component_add_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_menu_add"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="center"/>
Looking at the preview (EDIT: I mean the "Graphical Layout" tab of the xml editor in eclipse which uses the same rendering engine as all devices AFAIK) of component_add_button.xml you can see the image. Great. On the page which is including it it isn't displaying (although it does give you a selectable space where the image should be).
This seems like a really simple example that "should just work". The include tag has always seemed really flaky to me - I'm wondering if I'm missing something in terms of how it actually works...?
As your answer states, the eclipse preview does not display included layouts.
The simplest way to avoid doubt or mistakes in markup when "including" layout's is to design in the original layout then right click the view you wish to extract and select Extract include... from the menu
On a device this functionality worked fine. This seems like a bug in the "Graphical Layout" tab of the layout xml editor shipped with android-sdk.
I`m wondering about one thing. If I decide to have a part of my View same in every Intent. For example 2 buttons at the bottom of screen and for example I have 3 diffrent views, List, Detail and a third one :) Do I need to put the buttons on every xml schem for each view or can I create other xml and attach it in each activity with all listener etc.
If I can attach in activity how can I do that ?
Create a XML buttons.xml with the common elements
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:id="#+id/myButton"
android:src="#drawable/ic_title_search"
android:onClick="myHandle" />
<ImageButton
android:id="#+id/myButton2"
android:src="#drawable/ic_title_search"
android:onClick="myHandle" />
</merge>
Include it in another xml:
<include layout="#layout/buttons"/>
where buttons is the name of the xml file to be included
You can use the <include /> tag in your XML files.
See Layout Tricks for an example.
Create a separate layout for your buttons then in the layout you wish to display them use the include tag.
This will allow you to reuse the same layout in multiple parent layouts.
The include works as stated above you could also consider using fragments
Fragments
You can use these in older versions of Android by including the compatibility library in your application. It's definitely more work than a simple include but if you need some reusable UI for more sophisticated features than simple buttons you might want to look at that as well
How to use compatibility API