I'm using a USB connected device to run my app. In this practice app, I used an Android logo image to implement the zooming feature. When I try to change the image dimensions in the activity, it does not show the changes when the app imported into the usb device is loaded. The logo is simply zoomed to fit. But I want it to display the image with the way I see it in the Design view: http://i.imgur.com/hcaOHjW.png
I forked the code from this source to implement the zooming: http://www.c-sharpcorner.com/UploadFile/88b6e5/multi-touch-panning-pinch-zoom-image-view-in-android-using/
It does not have the double tap zoom in and out feature so let me know what I can add to implement that
And here is the code for my activity:
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.test.firstapp.Login"
android:id="#+id/activity_activity2"
android:focusable="false"
android:nestedScrollingEnabled="false">
<ImageView
android:layout_width="180dp"
android:layout_height="220dp"
android:id="#+id/botImg"
android:src="#drawable/bot"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"/>
in your java class try creating this view and then try changing the height and width parameters .inflate this view dynamically and assign parameters in the java itself dont use xml for this view .
Related
As i am going to make Alerting App, I am using my website instead of XML code. But for going to my alert activity for web Activity, I made an intent which works onclick on my small image view.
It's my XML code Below:
activity_web.xml
<?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=".WebActivity">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true">
</WebView>
<ImageView
android:id="#+id/imageView"
android:layout_width="81dp"
android:layout_height="75dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
tools:srcCompat="#drawable/bell_icon" />
</RelativeLayout>
But the main Problem is that imageview is not visible when I install's the app in my mobile.
It is also visible in my android Studio Layout.
You Check My Android Studio Layout here
Now tell me what should do for making visible it in final build apk which will work in my mobile.
you can set it properly by using constraint layout, here is a code maybe it's work!
In this i set an ImageView at the top and webview is set at bottom of ImageView.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<WebView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
you are using wrong attribute namespace, I'm supprised that AS preview tool is showing this image, it shouldn't. but your ImageView is there on device, it is clickable (wehn you set so), it just have transparent content (wrongly resolved srcCompat attr, as below). as a test you may add android:background="#789810" tag, ImageView will show up with visible background (still without image)
in your code you have
tools:srcCompat="#drawable/bell_icon"
tools namespace points on "some tools", like used tools:context=".WebActivity". for setting custom attribute of particular View you have to use (custom) resources namespace, these are declared in your XML with xmlns:app="http://schemas.android.com/apk/res-auto" line, thus you should use below line
app:srcCompat="#drawable/bell_icon"
btw. if you are using srcCompat the you should also use AppCompatImageView. it works with usual ImageView only because AS project by default is exchanging all ImageViews to AppCompatImageViews during building project to APK/bundle. this behavior may be changed or disabled, then your ImageView will stay without any image set. fully proper line for setting image is default src attribute of ImageView, so:
android:src="#drawable/bell_icon"
android namespace in here as this attribute belong to framework ("built-in"), not some additional library and View (AppCompatImageView comes from AppCompat or AndroidX library)
I am having a recyclerview inside a relative layout and the app is working fine, the navigation drawer is smooth. But I added an Imageview over the recycler view so that I can hide and show based on the availability of the data. But soon as I have added the Imageview the navigation drawer becomes very slow. And when I remove the Imageview it again works smooth. The image size is just 38kb. Can someone tell me how to show empty state in an efficient way
This is my Layout with the ImageView
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.test.sample.itemHistory"
tools:showIn="#layout/app_bar_item_history"
android:background="#ffffff">
<android.support.v7.widget.RecyclerView
android:id="#+id/materialList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageViewNoItems"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/noItems" />
</RelativeLayout>
Thanks in Advance
In my case, I try to load Image (PNG File within the Project Drawable Resource Folder) to my RecycleView's ImageView as well using Picasso and I facing the same problem where the Navigation Drawer sliding animation is being slow down.
I found that the main issue is because my Image File is quite Large so the Picasso load the Full Size image into the RecycleView's ImageView which would cause the Lag.
My Solution are: (I am using KOTLIN Language)
Re-size the image using Picasso built in resize function
Without Resize (Which Cause Lag):
Picasso.get().load(R.drawable.icon).into(holder.view.ImageView)
Resized (Solve Lag Problem):
Picasso.get().load(R.drawable.icon).resize(400,400).centerCrop().into(holder.view.ImageView)
Use setImageDrawable instead of Picasso
This Method does not required to Resize the image:
holder.view.ImageView.setImageDrawable(holder.view.ImageView.context.resources.getDrawable(R.drawable.icon))
used picasso or glide library for image loading.. and also add one line in your manifest and your project become smooth as before.
<application
android:largeHeap="true">
</application>
largeHeap is used to avoid outofmemory exception while loading images.
I'm trying to set up a background for my MainActivity in Android Studio, but it doesn't align properly on the top.
I've tried changing the device from Nexus 6P to Nexus 5 and Nexus 4 but it always looks the same.
This picture may help you understand the problem:
As you can see the gray triangle should be aligned at the top but there is a white line in the middle that I don't know how to remove.
This is my code, I'd really appreciate some help to fix this problem.
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#drawable/background"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="dancam.com.myapp.MainActivity">
</RelativeLayout>
I've tried also to set the android:layout_height to fill_parent but nothing changed
The theme that I'm using is Light_NoTitleBar
The Image I was using had a transparent gap above the gray triangle that caused the problem.
When I opened the image in android studio I was able to see the gap. Make sure you crop your images the right way!
I'm trying to allow users of my app to toggle the UI to be either standard orientation or "lefty flip". I'm unsure how low-level of a solution I need to program, considering Android might provide an abstracted way to easily do this.
Visually, the standard orientation would be:
and the lefty flip orientation would be:
So, currently what I'm thinking of attempting is a manual rearrangment of the xml layout, component by component, within a menu button's onTouch() logic.
I get the feeling that there may be a simpler way than this. Any suggestions? Is a series of programmatic calls to rearrange the view the best way? Xml file below.
<?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="horizontal"
android:baselineAligned="false"
android:keepScreenOn="true">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.40"
android:orientation="vertical"
android:id="#+id/toolbarGestureOverlay" >
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="3.60"
android:id="#+id/openglsurface">
</LinearLayout>
</LinearLayout>
I think you can achieve it by using rotate function (from API 11 only):
View view = findViewById(R.id.yourParentLayout);
view.setRotation(270);
// you must canculate your screen size to make your view fit your screen.
view.getLayoutParams().width = 800;
view.getLayoutParams().height = 480;
// For flip, you can rotate a long x or y axis:
view.setRotationY(180);
How to create below Image type of Progress ring in my Android app. I Want to show it 10 second before my whole app is loading on device. and also I want to rotate it. like window device rotate. Any Help be appreciated. I am new to Andorid.
Image :
I got the perfect answer.
Using this link I found the round progress ring.
progress_bar.gif
Then I Use this code :
animation.xml
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/progress_bar"
android:pivotX="50%"
android:pivotY="50%" />
In My main xml file.
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ProgressBar
android:id="#+id/progressbar1"
android:layout_marginTop="80dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="#anim/animation"/>
</RelativeLayout>
and finally output is :
u Can use the gifView library :https://github.com/koral--/android-gif-drawable
use this is your .xml:-
<pl.droidsonroids.gif.GifImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/src_anim"
/>
where src_anim is your loader gif file
Modifying the resource image of Progress Bar - this question recently has been discussed here. Check it out.
In short - you can use
custom drawable
animation-list
Both approaches allows to create progress bar like yours.
You can use this library to do it in a easier way. Furthermore, so many intuitive progressBar's type is available for you as well.
https://github.com/81813780/AVLoadingIndicatorView
Use Lottie animation.
See: https://github.com/airbnb/lottie-android
The LottieDrawable from library contains method progress(), which sets right frame if loaded image is progress image.