Posts Tagged with
Android
Use the Flutter Profiler to identify performance issues.
Use the Flutter DevTools to debug your app.
Reduce the number of widgets in your app and use lazy loading where possible.
Use the Dart compiler to optimize your code for faster execution.
Use the latest version of Flutter and its dependencies for better performance.
Avoid using large images and videos in your app, instead use smaller versions or thumbnails where possible.
how to add a slidey notification into your Android project
in Drawable:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#C999" /> <corners android:topLeftRadius="10sp" android:topRightRadius="10sp"/> <stroke android:color="#000000" android:width="1sp"/> </shape> in your layout XML
<TextView android:id="@+id/Message" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center" android:layout_gravity="bottom" android:textSize="10pt" android:padding="10dp" android:textColor="@android:color/black" android:background="@drawable/popup_background" android:text="POPUP MESSAGE" /> in Java :
the whole gravity / layout_gravity is a bit confusing, so here is a snippet:
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:gravity="center_horizontal|bottom"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Back " android:id="@+id/btn_back"/> </LinearLayout> The line of code that makes the button at the bottom is android:gravity="center_horizontal|bottom".
to get current project using mymodule in the ant build process. Add this line to default.properties in your Android project.
android.library.reference.1=../mymodule reference
If you already have a bitmap image in your code, just use this code snippet.
bmp = bmp.copy(Bitmap.Config.RGB_565, true); That code will recreate the bitmap image as a mutable. So you can edit that bitmap image on canvas as you like.
But if you do not have a bitmap image in code, create a new one using this code snippet.
Bitmap bmp=Bitmap.createBitmap(img.getHeight(),img.getWidth(),Bitmap.Config.RGB_565); where img is another bitmap image you want to make a new one with the height and width of it.
use android-gif-drawable library add the following dependency to build.gradle file of your project.
dependencies { implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' } Use the view in XML file like this.
<pl.droidsonroids.gif.GifImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/src_anim" android:background="@drawable/bg_anim" /> For more customization and code, see the docs here.
use VideoView on Android You can use VideoView to show the GIF image. But the library is more efficient and smooth.
use ImageView on Android Use ImageView and Split the GIF file into several images and then apply animation to it.
There are at least 3 ways to put imageview on another imageview.
Simple Order This way is just put the imageview after the other imageview in XML file. It is simple like that. The first view will be underneath the second one.
Using FrameLayout <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/t" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> </FrameLayout> The second image will be on top.
Use this code in your app’s `src/MainActivity.kt’ file.
import android.app.ActivityManager import android.app.ActivityManager.RunningTaskInfo import android.content.Context import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" val textView: TextView = findViewById(R.id.textView) val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager val recentTasks: List<RunningTaskInfo> = Objects.requireNonNull(activityManager).getRunningTasks(Int.MAX_VALUE) for (i in recentTasks.indices) { textView.text = "Application executed: ${recentTasks[i].
The idea is to use this code snippet.
ColorDrawable[] colorDrawables = { new ColorDrawable(Color.RED), new ColorDrawable(Color.BLUE), new ColorDrawable(Color.GREEN) }; TransitionDrawable transitionDrawable = new TransitionDrawable(colorDrawables); textView.setBackground(transitionDrawable); transitionDrawable.startTransition(2000); In this code snippet, we created a list of colorDrawables, then feed them to the TransitionDrawable. And now we have an animating color change, so we pass it to the setBackground to get the animating colors in the background. Got the idea ?
The main idea is to use view.setBackgroundColor(getColor(R.color.colorAccent)) to the selected view (list item). Let’s see a complete example.
use this xml code in res/layout/activity_main.xml. <?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:padding="8dp" tools:context=".MainActivity"> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> use this Kotlin code in src/MainActivity.kt. import android.os.Build import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.ArrayAdapter import android.widget.ListView class MainActivity : AppCompatActivity() { var operatingSystem: Array<String> = arrayOf("Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X") override fun onCreate(savedInstanceState: Bundle?