Create Android splash screen using SVG animation - svg

I am developing an app using Xamarin.Forms and I am trying to insert the splash screen to my Android project.
I found a few tutorials for creating a splash screen with a background color and a static png image, but I want to use my svg animation as splash screen. I thought I could follow a tutorial for static image and just replace the png image with the svg animation, but it didn't work. Here's what I have so far:
On SplashActivity.cs:
[Activity(Label = "SplashActivity", Theme = "#style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
async void SimulateStartup()
{
await Task.Delay(5000);
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
On MainActivity.cs:
// I only changed the MainLauncher property to false
[Activity(Label = "MyApp", Icon = "#mipmap/icon", Theme = "#style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
...
}
On styles.xml (in the Xamarin.Android project):
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">#drawable/desenhando5s</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="colorPrimaryDark">#004632</item>
</style>
When I run the application, it only shows a black screen as splash screen and then shows my login page as always.
Can anybody tell me what I have to do to set my animation as the splash screen?
(FYI: in case anyone wants to know, I created the animation using SVGator)

You could use FFImageLoading to load your svg image in your SplashActivity instead of set it in styles.xml.
Splash screen:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FFImageLoading.Views.ImageViewAsync
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Code:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.layout5);
var filePath = "check";
var imageView = FindViewById<ImageView>(Resource.Id.imageView);
ImageService.Instance.LoadCompiledResource(filePath).WithCustomDataResolver(new SvgDataResolver(64, 0, true)).Into(imageView);
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
async void SimulateStartup()
{
await Task.Delay(5000);
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
Updated:
Please check the screenshot. The .svg image is in the drawable folder. The layout5 is the splash screen in the layout folder.

Related

Android - hide status and navigation bar completely for an app with nav drawer and app bar

How can I dynamically hide the status and the navigation bar completely?
The app contains a regular navigation drawer with a appbar / toolbar and FAB buttons.
When switching to full screen, the content of the navigation and the status bar is scrolled away. Two empty bars are left on the screen. I want those empty bars to hide.
I created a minimal demo app. On the left is the regular app. When pushing on the fab, the app should be shown fullscreen.
How can I get the bars to hide?
QUESTION: Please write which change(s) are needed in the minimal demo project?
Updated with a second solution:
The GREAT solution provided by #Roaim works. Essential was to set the android:fitsSystemWindows layout property to false.
If you still have trouble with the showing and hiding of status/navigation bars, this solutin may help you.
Hide the bars completely:
public static void hideSystemUI() {
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
And show all bars:
public static void showSystemUI() {
if (getSupportActionBar() != null) {
getSupportActionBar().show();
}
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
Update
The issue was with your layout file. I just set android:fitsSystemWindows=false to fix the issue. I made a pull request to your repo, which I think solves your issue.
You should follow the following official documentations:
Hide the status bar
Hide the navigation bar
Hide the Status Bar on Android 4.0 and Lower
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
...
}
Hide the Status Bar on Android 4.1 and Higher
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
Hide the Navigation Bar
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Go in values>styles
Now In App theme use
To make navigation bar transculate
<item name="android:windowTranslucentNavigation">true</item>
To remove it make its color matched with your layout
<item name="android:navigationBarColor">#color/white</item>
OR Try this
public void FullScreencall() {
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if(Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
}
}
Try this...
<style name="MyApp" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
...
</style>
Try this to hide/show statusbar and navbar, both are parts of SystemUI.
fun setSystemUIVisibility(hide: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val window = window.insetsController!!
val windows = WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars()
if (hide) window.hide(windows) else window.show(windows)
// needed for hide, doesn't do anything in show
window.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
} else {
val view = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = if (hide) view else view.inv()
}
}
Theme
<style name="Theme.FullScreen" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item>
</style>
AndroidManifest
<activity android:exported="false"
android:name=".FullScreenActivity"
android:screenOrientation="fullSensor"
android:theme="#style/Theme.FullScreen"/>

Only the original thread that created a view hierarchy can touch its views exception when using thread in OnCreate method Xamarin.Android

I have the following screen:
When I click on Ponentes ImageButton , after few seconds SpeakersActivity opens. After clicking on Ponentes ImageButton I don't want to stay on its screen for several seconds, but I want SpeakersActivity to open immediately with loadingSpinner ProgressBar while the data in SpeakersActivity is loading. I put the code which causes the delay in a thread in the OnCreate method of SpeakersActiviy:
protected override async void OnCreate(Bundle savedInstanceState)
{
.....
.....
loadingSpinner.Visibility = ViewStates.Visible;
await Task.Run(() =>
{
//get all the speakers from the db
allSpeakers = DatabaseHelper.GetAllFromTable<Speaker>("speakers.db");
//get only the international spakers
internationalSpeakers = allSpeakers.Where(x => x.Nationality.Equals("international")).ToList();
//get only the national speakers
nationalSpeakers = allSpeakers.Where(x => x.Nationality.Equals("national")).ToList();
//fill in the RecyclerView with data
speakersRecyclerView = FindViewById<RecyclerView>(Resource.Id.speakersRecyclerView);
speakersLayoutManager = new LinearLayoutManager(this);
speakersRecyclerView.SetLayoutManager(speakersLayoutManager);
speakersAdapter = new SpeakersAdapter(speakers);
speakersAdapter.ItemClick += OnItemClick;
speakersRecyclerView.SetAdapter(speakersAdapter);
loadingSpinner.Visibility = ViewStates.Gone;
});
.....
.....
}
I get Only the original thread that created a view hierarchy can touch its views exception. What is the cause of that exception and how can I achieve what I want? If there is a single command solution as mine:
await Task.Run(() => {.....});
it would be better, so if another person reads my code in the future, he doesn't wonder too much what's going on.
Here is the SpeakersActivity.axml :
<LinearLayout>
<Toolbar>
<TextView/>
</Toolbar>
<LinearLayout>
<TextView/>
<TextView/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id = "#+id/speakersRecyclerView"/>
<ProgressBar
android:id = "#+id/loadingSpinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminateDrawable="#drawable/animdraw"
android:visibility="gone"
android:layout_gravity="center"/>
</LinearLayout>
I skipped View's attributes because they are irrelevant.
This is a thread issue, What you need to know is that all the Views that are generated on your UI are created in the MainThread which is also called as UIThread.
Now, this is a general concept that if you have a View only the thread that creates it can modify it i.e. the UIThread now the question arises how do you do that when the code running is on a Background or a secondary thread regardless of who created it? So the platform that you use usually gives that way to you.
For instance Android,
Android has a method in its Activity class which is called RunOnUiThread now this is the method that you use when there is something that needs to be done on the UI but you are on a background thread. iOS has a method too which is called InvokeOnMainThread, XF has BeginInvokeOnMainThread!
Now, for your situation, you add a background task that lazy loads your View, which is cool now you need to understand that this is not on the main thread as you created a Task that is supposed to run on another thread through Task.Run so now you use the Trick method that we talked about where ever you play with the Views:
Note I might miss something because I do not know the whole code but you can do the rest on your own if you get the basics so here goes nothing:
protected override async void OnCreate(Bundle savedInstanceState)
{
.....
.....
loadingSpinner.Visibility = ViewStates.Visible;
await Task.Run(() =>
{
//get all the speakers from the db
allSpeakers = DatabaseHelper.GetAllFromTable<Speaker>("speakers.db");
//get only the international spakers
internationalSpeakers = allSpeakers.Where(x => x.Nationality.Equals("international")).ToList();
//get only the national speakers
nationalSpeakers = allSpeakers.Where(x => x.Nationality.Equals("national")).ToList();
RunOnUiThread(()=>
{
//fill in the RecyclerView with data
speakersRecyclerView = FindViewById<RecyclerView>(Resource.Id.speakersRecyclerView);
speakersLayoutManager = new LinearLayoutManager(this);
speakersRecyclerView.SetLayoutManager(speakersLayoutManager);
speakersAdapter = new SpeakersAdapter(speakers);
speakersAdapter.ItemClick += OnItemClick;
speakersRecyclerView.SetAdapter(speakersAdapter);
loadingSpinner.Visibility = ViewStates.Gone;
});
});
.....
.....
}
Goodluck feel free to get back if you have questions!
It's working, the only issue is that the loadingSpinner ProgressBar is spinning during half of the loading time. For example, if it takes 4 seconds to load SpeakersActivity after Ponentes ImageButton has been clicked, the loadingSpinner is spinning for 1 or 2 seconds and then it stays still until SpeakersActivity data is shown, like that:
Here is the whole SpeakersActivity code:
[Activity(Label = "SpeakersActivity", ScreenOrientation = ScreenOrientation.Portrait)]
public class SpeakersActivity : BaseActivity
{
TextView internationalSpeakersTextView;
TextView nationalSpeakersTextView;
RecyclerView speakersRecyclerView;
// Layout manager that lays out each card in the RecyclerView:
RecyclerView.LayoutManager speakersLayoutManager;
// Adapter that accesses the data set (speakers):
SpeakersAdapter speakersAdapter;
/// <summary>
/// List that contains all the speakers
/// </summary>
List<Speaker> allSpeakers;
/// <summary>
/// List that contains the international speakers
/// </summary>
List<Speaker> internationalSpeakers;
/// <summary>
/// List that contains the national speakers
/// </summary>
List<Speaker> nationalSpeakers;
ProgressBar loadingSpinner;
protected override async void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.SpeakersActivity);
Android.Widget.Toolbar toolbar = FindViewById<Android.Widget.Toolbar>(Resource.Id.toolbar);
toolbar.NavigationOnClick += delegate
{
this.OnBackPressed();
};
loadingSpinner = FindViewById<ProgressBar>(Resource.Id.loadingSpinner);
loadingSpinner.Visibility = ViewStates.Visible;
await Task.Run(() =>
{
//get all the speakers from the db
allSpeakers = DatabaseHelper.GetAllFromTable<Speaker>("speakers.db");
//get only the international spakers
internationalSpeakers = allSpeakers.Where(x => x.Nationality.Equals("international")).ToList();
//get only the national speakers
nationalSpeakers = allSpeakers.Where(x => x.Nationality.Equals("national")).ToList();
RunOnUiThread(() =>
{
speakersRecyclerView = FindViewById<RecyclerView>(Resource.Id.speakersRecyclerView);
speakersLayoutManager = new LinearLayoutManager(this);
speakersRecyclerView.SetLayoutManager(speakersLayoutManager);
LoadSpeakers(internationalSpeakers);
loadingSpinner.Visibility = ViewStates.Gone;
});
});
internationalSpeakersTextView = FindViewById<TextView>(Resource.Id.internationalSpeakersTextView);
internationalSpeakersTextView.Click += delegate
{
//change TextViews's style when selected/not-selected
internationalSpeakersTextView.SetBackgroundResource(Resource.Drawable.textView_selected);
nationalSpeakersTextView.SetBackgroundResource(Resource.Drawable.textView_unselected);
LoadSpeakers(internationalSpeakers);
};
nationalSpeakersTextView = FindViewById<TextView>(Resource.Id.nationalSpeakersTextView);
nationalSpeakersTextView.Click += delegate
{
//change TextViews's style when selected/not-selected
nationalSpeakersTextView.SetBackgroundResource(Resource.Drawable.textView_selected);
internationalSpeakersTextView.SetBackgroundResource(Resource.Drawable.textView_unselected);
LoadSpeakers(nationalSpeakers);
};
}
/// <summary>
/// Load speakers inside activity
/// </summary>
/// <param name="speakers">speakers</param>
private void LoadSpeakers(List<Speaker> speakers)
{
speakersAdapter = new SpeakersAdapter(speakers);
speakersAdapter.ItemClick += OnItemClick;
speakersRecyclerView.SetAdapter(speakersAdapter);
}
private void OnItemClick(object sender, string speakerResumeUrl)
{
var speakerDetailsActivity = new Intent(this, typeof(SpeakerDetailsActivity));
speakerDetailsActivity.PutExtra("speakerResumeUrl", speakerResumeUrl);
StartActivity(speakerDetailsActivity);
}
public override void OnBackPressed()
{
StartActivity(typeof(CongressActivity));
Finish();
}
}
Here is ProgressBar view from SpeakersActivity.axml:
<ProgressBar
android:id = "#+id/loadingSpinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminateDrawable="#drawable/animdraw"
android:visibility="gone"
android:layout_gravity="center"/>
And here is animdraw.xml:
<?xml version="1.0" encoding="utf-8" ?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/spinner"
android:fromDegrees="0.0"
android:pivotX="50.0%"
android:pivotY="50.0%"
android:toDegrees="360.0" />

Facebook like and comment not working on Android webview

I have tried webview with Android studio and FB share and other social media share buttons are working fine. But FB direct like and comment button on my website is not working. When I press like button I can see white screen with left top screen number "1". Please kindly help me.
MainActivity.Java
package com.example.neermaicom;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import static android.content.Intent.*;
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
webView = findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url == null || url.startsWith("http://") || url.startsWith("https://")) return false;
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} catch (Exception e) {
return true;
}
}
});
webView.loadUrl("http://www.neermai.com");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
//This method require to use back button if want to go previous web page
#Override
public void onBackPressed() {
if(webView.canGoBack()){
webView.goBack();
}else {
super.onBackPressed();
}
}
Activity_main.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=".MainActivity">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
This is due to the Facebook user auth, unfortunately android webview is not fully compatible with auth systems, an alternative that I use in my webview applications is to use "Chrome Custom Tabs" to auth access to the system of comments that I use.
In my application when the user clicks on comment, a Google Chrome tab is opened inside my application showing the comments page, when the user is not logged, the chrome auth the user without having to close or minimize my application to open google chrome. Everything is done within my own application.
To start the Chrome Tab when I added an "Intent" to shouldOverrideUrlLoading, below is an example of my code.
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("#comments")){
Uri uri = Uri.parse(url);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.build().launchUrl(PostActivity.this, uri);
return true;
}
else {
view.loadUrl(url);
return true;
}
}
And in Gradle app:
implementation 'androidx.browser:browser:1.3.0-alpha01'
My url for comment pages has "#comments" you change to something standard that you have in your comment page URLs or if the facebook comment system is directly on the post page, put something that is standard in the url of your posts to open in the google chrome tab.

cannot find symbol variable imageView2

I am just starting with Android Studio. I got some code from the web on how to ass a splash screen to my app, but it has compiling errors. I could use some help.
the errors are:
error. can not find symbol variable imageView2
error. can not find symbol variable s_img
error. can not find symbol variable s_image_black
error. can not find symbol variable s_image_black
I know this is due to my lack of knowledge, but I am just starting and trying to use this example to learn. Any help would be much appreciated.
Cheers
Paul
package org.quaestio.kotlinconvertedwebview;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.ImageView;
import org.quaestio.kotlinconvertedwebview.MainActivity;
import java.util.Random;
public class Splashscreen extends Activity {
Thread splashTread;
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
imageView = (ImageView)findViewById(R.id.imageView2);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
int[] ids = new int[]{R.drawable.s_img,R.drawable.s_image_black, R.drawable.s_image_black2};
Random randomGenerator = new Random();
int r= randomGenerator.nextInt(ids.length);
this.imageView.setImageDrawable(getResources().getDrawable(ids[r]));
splashTread = new Thread() {
#Override
public void run() {
try {
int waited = 0;
// Splash screen pause time
while (waited < 3500) {
sleep(100);
waited += 100;
}
Intent intent = new Intent(Splashscreen.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
Splashscreen.this.finish();
} catch (InterruptedException e) {
// do nothing
} finally {
Splashscreen.this.finish();
}
}
};
splashTread.start();
}
}
activity_splashscreen below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#feffc3"
android:layout_gravity="center"
android:id="#+id/lin_lay"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/splash"
android:background="#drawable/splash_img" />
</LinearLayout>
The problem is that you're setting an id wich don't correspond with the xml file. For example imageView = (ImageView)findViewById(R.id.imageView2); you need to change imageView2 with your xml imageview id wich is "splash". For the pthers error you need to check that files in the drawable folder.
Hope it was helpful
The ImageView in your xml has id splash, so in your code, instead of:
imageView = (ImageView)findViewById(R.id.imageView2);
you should do
imageView = (ImageView)findViewById(R.id.splash);
Also, this line:
int[] ids = new int[]{R.drawable.s_img, R.drawable.s_image_black, R.drawable.s_image_black2};
assumes that in your drawable folder there exist all these drawables:
s_img, s_image_black, s_image_black2
but apparently they don't, so you have to copy or create them and put them in the drawable folder.

Camera SurfaceView flicker in view pager while scrolling

In my App I am using ViewPager with FragmentStatePagerAdapter to display 4 different layout.
Layout 1 , 3 , 4 consists of ListView and 2nd layout contains SurfaceView Camera. Now when I am scrolling horizontally camera at the both edges get flicker.
I search on google, and find different solutions. like
1) giving minus margin with android:layout_gravity = "center".
2) viewPager.requestTransparentRegion(viewPager);
Here in first case, it works good at first time but when comming back from resume it cuts from right showing black rectangle.
also I have also tried with different parent layout but the same scenario
happened and also tried to give margin programmatically, but could not find any solution.
Here is my Camera xml.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="#+id/surface_view"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_marginRight="-100dp"
android:layout_marginLeft="-100dp"
android:layout_height="match_parent"
android:visibility="visible" />
</LinearLayout>
and here is my fragment adapter.
public class DashboardAdapter extends FragmentStatePagerAdapter {
public DashboardAdapter(FragmentManager fm) {
super(fm);
fragmentList = new ArrayList<>();
fragmentList.add(new InboxFragment());
fragmentList.add(new CameraFragment());
fragmentList.add(new ContactFragment());
fragmentList.add(new AddFriendsFragmnet());
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return InboxFragment.newInstance(position);
case 1:
return CameraFragment.newInstance(position);
case 2:
return ContactFragment.newInstance(position);
case 3:
return AddFriendsFragmnet.newInstance(position);
default:
return CameraFragment.newInstance(position);
}
}
#Override
public int getCount() {
return 4;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
return fragment;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
}
}
Any help would be too much thankful.
I have replaced SurfaceView with TextureView to open a camera.
Link
Here is a link for an example of TextureView Camera. It's working now.
Thanks

Resources