Modified source of custom view in library wont affect on XML layout - android

I'm using in my project this library with custom ImageView which is able to handle pinch zoom and double tap zoom events: https://github.com/jasonpolites/gesture-imageview. I need to change in that library's source few things, because I want to use it with ViewPager. The problem is that the when I modifying source code of custom view in library and after this I adding this modified custom view to layout in XML file like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gesture-image="http://schemas.polites.com/android"
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000">
<com.polites.android.GestureImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
gesture-image:min-scale="0.75"
gesture-image:max-scale="10.0"
android:src="#drawable/image"/>
</LinearLayout>
my changes don't want to appear, I'm breaking source code (for testing) by changing all values from 0 to 100, when I creating layout programatically my changes appears, and custom view works as i assumed, but when I definie layout in XML there's no effect, even if I clean up some java files of library from source code custom view in XML layout still works like there's no change in source.

Have you tried Project => Clean of both your main project and the library?

Related

Android: Is there any specific place on the document to find explicit XML reference?

Android documentation for XML is too hard to find. Whatever I get is all Java related documents. I am a newbie to Android and trying to find XML references for Views and Widgets. For now, I am searching for Checkbox but it I am struggling to get XML reference every time for any component.
Can anyone help me to learn how to find and use the reference documents especially for XML and its attributes?
Million thanks.
The XML attributes are referred;
The CheckBox is created from inheriting CompoundButton, TextView etc.
Each view has its own XML attributes. So for CheckBox all the inherited values are applicable. For instance ChackBox has Button bahaviour, TextBox behaviour etc. Hence all above apply for the CheckBox. So if you want to add Button related behavior of CheckBox refer above 'Button Attributes'. If you want to add Text related behavior of CheckBox refer above 'TextView Attributes' etc.
Also refer https://developer.android.com/reference/android/R.styleable
Sample layout xml as follows;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/llMainFill"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<ListView android:id="#+id/lvLog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>

Android Studio: Can you display a view just for preview?

My app has a lot of views that are containers for fragments (which load an image and other views) and depend on an API to fetch images. To make the development of the design easier, I like to add a sample of that image in my xml. Right now, I'm adding a RelativeLayout with the FragmentContainer and a dummy ImageView using different visibility values for android:visibility and tools:visibility.
Is there a better way to show images just for preview purposes ? I'd like to have the preview Views not compiled in the release version.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:adjustViewBounds="true"
tools:src="#drawable/image"
tools:visibility="visible" />
<RelativeLayout
android:id="#+id/FragmentContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
If I understood your problem correctly, you could do something like this:
instead of using dummy views, use
<include tools:layout="#layout/layout_preview" layout="#layout/layout_actual"/>
where layout_preview.xml is whatever you want to use only in the preview, and layout_actual.xml is what will be used in the app
in case you wanted to only add a view in the preview, but have no view at all in the app, you can use a layout_actual.xml with an empty merge tag
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"/>
if you don't want to include useless layout, you might want to create the dummy ones only for debug build type, it will show an error in the layout because layout_dummy will be missing but since it's tools attribute you should be able to compile and run

Within a new activity, ViewImage does not show an image

I created an Activity, which I load from a fragment within my "main" activity.
Within this new activity I placed an ImageView with an image from my drawable directory (I have about 10 other drawables I present the exact same way in the main activity).
The problem is that although in the IDE I see the image, it is not displayed in run time (via the simulator).
-- to clarify, the image is static hence the difference compared to other questions (I'm not loading it by code).
Any ideas on how to solve it?
My hunch is that it relates to the fact it's a new activity, but I'm new to android development, so I can't base it on any knowledge...
I did not add any code to the java section of the activity (didn't touch any "on.." nor added functionality to this specific file)
P.S. I tried cleaning the project, tried presenting an image that is presented on the main activity, and restarting anything that I can... nothing helped :(
My Activity xml is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="reducted">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/manageSubscriptionScreenLogo"
android:layout_width="match_parent"
android:layout_height="110dp"
app:srcCompat="#drawable/managesubscription_header" />
</LinearLayout>
</RelativeLayout>
It doesn't matter I take the ImageView and place it outside of the LinearLayout (and remove it), or change the size to wrap_content or match_parent (I tried all combinations), the image is not presented.
How it looks in the IDE:
And how it looks in run time:
Try using android:src="#drawable/managesubscrip_header" instead of app:srcCompat="#drawable/managesubscription_header" in ImageView to avoid automatic scaling of the drawable.
Let me know if it helps

Eclipse Content Assist Not Working Properly For Android Layout

Whenever I have Views inside a ViewGroup inside a android.support.v4.widget.DrawerLayout, Eclipse's autocomplete starts working weird. It doesn't display most of the properties
Example with DrawerLayout -> LinearLayout -> ImageView:
In the previous screenshot, you can see that I typed "android:scale..." and the IDE's intellisense isn't showing me the ImageView's android:scaleType
If I use Eclipse's Properties window for the ImageView, I can see that it is only displaying the basic properties for "View" (and not for ImageView...):
Now if the ImageView is not a descendant of the DrawerLayout and I put it somewhere else, the autocomplete works properly:
I've seen related questions such as:
Autocomplete does not work in XML files in particular hierarchy
Content Assist doesn't work in xml with support library
but they have been dead with no answers for quite a while...
Content assist doesn't work for Views (be it TextViews, EditText, Buttons...) that I add inside the DrawerLayout. It only suggests the 'basic' properties.
Does anybody know why this happens or how to fix this?
Sample layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/some_image" />
</LinearLayout>
<RelativeLayout
android:id="#+id/drawer_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
Just to give some closure to this 5 months-old question, I'll quote and link to Atul O Holic's answer. Thanks to Dileep Perla for pointing me there.
When using support package Widgets this is a common scenario (a weird
one too).
Here you using, android.support.v4.widget.DrawerLayout and hence the
issue. Happened with me a lot of time.
You can also try couple of options mentioned here.
I've found that using the tag can be handy in this case. Just put your layout that is inside the drawer in a separate layout file and then include it inside the drawer layout.

Avoid to rewrite code for activities with the same layout

I'd like to run several Activities on my Application;I'd like each Activity to have a Linear Layout and to show an image as heading; basically I'd like every layout to start like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/Grey"
>
<ImageView android:id="#+id/imageHeader" android:src="#drawable/tf_header" android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#color/Black" android:scaleType="fitXY"></ImageView>
Is it possible not to reapeat this code for each layout? Could I use themes or styles to avoid it? Thank you for your replies.
Yes thats possible use the <include> tag as described in Layout Tricks.
For your example I would add the image as <include> and have a LinearLayout in each Activity layout xml
One of my apps uses the same xml file for 30 or so classes, i just modify it in code to customize it. That approach may work, just leave every label in the xml blank and set it in the .class

Categories

Resources