Android: set all view to visible for testing/ debugging purposes - android

I was wondering wheather when previewing the layout in Android Studio I can see all view regardless of their visibility in order to inspect all the elements in the preview without changing something in the code (just for debugging purposes).
Thanks in advance!

you can use:
android:visibility="gone"
tools:visibility="visible"
the tools namespace is there for this type of situation where it's only relevant for development.
and then just import:
xmlns:tools="http://schemas.android.com/tools"
in your root layout, if your IDE doesn't suggest it

Related

Is it possible to scroll a ScrollView with a ConstraintLayout in Blueprint Mode?

So I have been developing this layout using a ConstraintLayout inside a ScrollView. It works fine, but now I have hit a problem. I have to expand the layout outside the screen. I can scroll in Design mode, but I cannot add anything without it getting stuck to the top. The constraints are for earlier objects, not the current one I'm adding.
I can add constraints in Blueprint mode, but it looks like I cannot scroll the ScrollView in blueprint mode. Is this even possible? Using Android Studio 2.2(release) and constraint-layout:1.0.0-alpha8
I tried doing it like in Design mode, but it doesn't scroll. Any ideas?
Scrolling normally with ConstraintLayout causes the constraints to stay in the same location.
EDIT:
Updated to alpha9 but still does not solve it
EDIT 2:
beta1 does not work either. AS 2.2.2.
EDIT 3:
Sample layout:
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sampleButton"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText">
<android.support.constraint.ConstraintLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- ETC constraints -->
</android.support.constraint.ConstraintLayout>
</ScrollView>
In android studio 2.2 update, it includes scrolling in design and blueprint mode by default. click on design mode in the preview pane and try to scroll your screen it will start scrolling. There is another option of blueprint in that mode it shows you the blueprint of the design and by doing same for this will help you scroll in blueprint mode also.
Put the Scroll view outside of the Constraint layout. Then use this [Red mark] to drag the view and it will make a custom device editor to you. When you have done, change back to the device editor [Beside rotation icon]...
In latest android studio 2.2.2 version with constraint-layout:1.0.0-beta1 you can scroll blueprint
for better working, after updating constraint-layout please restart android studio (invalidate caches)
Not yet.
Maybe try to have a separate file to edit the content instead, and use an include in the file where you have the ScrollView?
As of ConstraintLayout 1.0.1 scrolling scrolls the constraints. Meaning it is possible to scroll a ConstraintLayout in blueprint mode and it functions as expected. It works at Android Studio 2.3.2 and up (I haven't older versions).
Now when scrolling, both the visible view, the border, and constraints move along with the drawn button.
beta1 version has been released. I doubt this is fixed, but check it out.
You can ask for a bugfix for this here: http://tools.android.com/feedback
PS: you are trying to scroll using the mouse scroll wheel, right? hehe just checking... I say that because just recently I figured out I could scroll in the design mode using the mouse wheel.. duhh haha. I never tried in blueprint mode though.

Objects visibility

I've done a lot of search but can't find the difference between tools:visibility = "visible" and android:visibility = "visible" ? Which situation I must use tools or android?
Here is the Simple Explanantion:
tools:visibility = "visible" is used to manipulate view visibility on the IDE.It wont affect the view in the real time.It just used for Designing purpose in Android Studio
while
android:visibility = "visible" is the actual code which will be executed in run-time and will make changes to your views
Ref: http://tools.android.com/tips/layout-designtime-attributes
tools: attributes only contribute to design time preview while editing layouts while
android: actually affects how it will be displayed on actual device.
You can find further information here and here.
The exactly question should be
"What the difference between android:... and tools:... on Layout
XML files"
tools is one of the Design Attributes that can facilitate layout creation in XML in the development framework.This attribute is used to show the development framework what activity class is picked for implementing the layout. Using “tools:context”, Android Studio chooses the necessary theme for the preview automatically
Android is used in run-time app, when you launch your apk in a device
according to here
If you see the Design Time Layout Attributes
The tools namespace is a specially recognized namespace by the Android tools, so all the attributes you define on view elements in the tools-namespace will be automatically stripped when the application is packaged and there is no runtime overhead.
So if we need to test something in layout editor only during development time which doesn't affect at runtime, we can use the tools namespace.
Example:
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First"
tools:visibility="invisible" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second"
tools:visibility="visible" />
If the above layout is rendered in Android Studio designer view, first Button will be invisible. But at run time, it will be visible.
TOOLS values will be used only in layout preview in Android Studio.t
ANDROID values will be used in app as normal.
So if you set values for main container:
tools:visibility:"gone"
android:visibility:"visible"
The main container in layout preview in AS will be gone, but if you launch app on emulator / device it will be visible.

ViewPager preview layout in Android Studio

Is it possible to show a preview layout for ViewPager in AndroidStudio like in ListView/RecyclerView/etc.?
Short answer: No.
I think you're talking about ViewPager from ViewPager 2. My answer will be assuming ViewPager 2. Pls update the question to clarify that.
- Workaround: a hidden include
<include
android:visibility="gone"
tools:visibility="visible"
layout="#layout/item_that_shows_inside_viewholder"/>
And I agree that's a very poor way to do it.
If in constraint layout you can loosely match the same constraints to make this show on top. And yes, you will inflate this in production code so you may incurr in performance slow down depending on what you have there.
It's very unfortunate that tools:layout doesn't exist or work properly (yes, I got inconsistent results while trying it).
- 2nd less worst way is using isInEditMode on code on the parent class
something in the fashion of
class CustomView ....
init {
// inflate layout that contains ViewPager
if ( isInEditMode() ) {
//do something that replaces ViewPager with its inflated view holder
}
}
which has served me well when I can use that. However that's unsuitable for most places.
- If at least ViewPager were not final we could extend and do some tricks there using isInEditMode like above.
- You can make a custom class wrapper with internal field ViewPager
One way that does certainly work is making your custom class extend FrameLayout and having an internal view that is your actual ViewPager. But then you have to re-implement and delegate all its methods, which is a big pain. Maybe kotlin has a way to do that, but so far I don't know how. Or maybe using reflection or kotlin poet could be a way to do that. It's too risky for my taste.
- If we could make a databinding adapter to do the isInEditMode like above it would work. But databinding adapters don't run in preview.
- I tend to think these tools attributes get processed by Android Studio, so it would take probably an android studio plugin to work around it.
This is the current full list of tools attributes: https://developer.android.com/studio/write/tool-attributes.html#toolslistitem_toolslistheader_toolslistfooter
It may be useful reading this Android XML Is there a way to use the tool namespace with custom attributes?
where a library to read custom attributes with tools gets mentioned. There may be an alternative with this library, but I have never used it and not sure how it works:
https://github.com/giljulio/sneakpeek
I'd love to be proved wrong, but in my opinion all of the options are dead ends or too much effort.
In Andriod studio some views are shown in run time but not in compile time. Think about Frame Layout as a container for fragment transaction. We may place any kind of views on that container in run time. So, it's not possible to show a view while coding. The viewpager is playing same kind of role here. So, we can't show a view there before running and actually placing a fragment/other view there.
I hope you are clear now. :)
This is possible, when putting the ViewPager into it's own XML layout resource.
Alike this one can show the desired Fragment instead of the ViewPager:
<fragment
android:id="#+id/fragment_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="#layout/fragment_viewpager"
tools:layout="#layout/fragment_preview" />
This also provides the XML preview for the navigation graph design view.
tools:layout only works with fragment, but not with include.
i think it's not...some of the layouts have no preview while coding or designing ...like TabLayout
Although I don't think there is such a functionality out of the box, I used the following workaround to achieve design time preview for the ViewPager:
Add an <include> with the view that you will use in your ViewPager as a layout,just after the ViewPager itself
Set tools:visibility="visible" and android:visibility="gone" to this <include> view so that it will be visible at design time but not at runtime. Also set tools:visibility="gone" to the ViewPager so that it will be invisible at design time.
The idea is to hide ViewPager at design time and show its contents instead while doing the opposite at runtime. This should work for other controls as well.
To show an example:
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/tabl1"
tools:visibility="gone">
</androidx.viewpager.widget.ViewPager>
<include
layout="#layout/fragment_example1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintTop_toBottomOf="#id/tabl1" />
I hope this helps you

Tools namespace android listitem

I'm trying to use the "tools" namespace feature in Android Studio.
I'm trying to populate the ListView with dummy list items, for design purposes. The link here says the tools:listitem="#android:layout/<filename>" should do.
But for some reason, Android Studio keeps showing Layout android:<filename> does not exist. I'm trying to find a solution for it, so I don't have to run my app again and again with dummy values for testing.
I might be overlooking something very foolish, so forgive me. Here is what I have for now:
<ListView
android:id="#+id/controllerProfiles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
tools:listitem="#android:layout/profiles_list_item"/>
And I have a file profiles_list_item.xml under res/layout. Any suggestions or alternatives?
you should change the following line :
tools:listitem="#android:layout/profiles_list_item"
to this :
tools:listitem="#layout/profiles_list_item"
with #android you say that you want to use a layout from android resources but your layout is in your own project files.
tools:listitem doesn't work with ListViews in Android Studio 2.2. This is a known bug. I've tested this in Android Studio 2.3 beta 1 and it is fixed here.
You can also move from ListView to RecyclerView as this bug doesn't occur at RecyclerViews.

Is there a way to preview a fragment being used in another view in IntelliJ IDEA 12?

I recently made the switch from Eclipse to IntelliJ IDEA 12. Is there a good way to preview a fragment being used in another xml layout file?
In Eclipse there's a way to specify which fragment I'm using which is pretty helpful.
Edit (clarification):
What I'm referring to is the ability to view a Fragment being referenced in another xml layout. Say I'm creating a Profile screen (activity_profile.xml) and want to include a fragment (fragment_pic.xml) that contains a picture, name, etc. When I include the fragment in the activity_profile.xml, it doesn't display in the preview for the activity_profile layout. It just displays "<fragment>"
You can do this in the XML:
<fragment
android:name="com.yourpackage.yourapp.yourfragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:layout="#layout/fragment_layout"
</fragment>
The tools namespace is qualified by this in the top view, same as xmlns:android namespace qualifier:
xmlns:tools="http://schemas.android.com/tools"
I had this same issue as well after moving from Eclipse to the Android Studio Preview though thankfully Android Studio suggests you provide this in the XML when it checks your definitions, very handy :)
I think you mean the GUI designer. To switch between xml view and designer view, click on the buttons circled in red.

Categories

Resources