I am using motionlayout to handle animations since it's seems like a good choice. One of the animation i should implement required to alter the src of the image and i couldnt animate that.(seems like we cant change src attribute of an image in constraintsets of motionlayour scene file) Then i found its posssible to crossfade two images with ImageFilterView. I finish the job and switch to another activity, there i need same resource and as you expect i used it but it didn't appeared. I thought this is related with something else, i try many different ways to find out but after some time I found its because motion layout. when i use the image as altsrc with imagefilterview and if its somehow ended up faded state this image will not be visible even if you use it in another activity. it keeping its state across the whole app. What i am wondering is this a bug or some "supposed to be" way logic?
Edit:
upon #hoford request I create a new project just to test it. and it happened again.
Basically what i am try to do is move an image from right side of the screen to left side when clicked. meanwhile its should fading to another image. and doing the opposite on second click
Here is what i do:
MainActivity.java:
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.utils.widget.ImageFilterView;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class MainActivity extends AppCompatActivity {
MotionLayout _motionlayout;
boolean isForward = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_motionlayout = findViewById(R.id.rootlayout_motionlayout);
ImageFilterView imageFilterView = findViewById(R.id.about_imagefilterview);
isForward = true;
imageFilterView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (isForward) {
Log.d("TAG", "onClick: inside if");
_motionlayout.setTransition(R.id.mainactivity_transition_about_icon_1);
_motionlayout.transitionToEnd();
isForward = false;
} else {
Log.d("TAG", "onClick: inside else");
_motionlayout.setTransition(R.id.mainactivity_transition_about_icon_2);
_motionlayout.transitionToEnd();
isForward = true;
}
}
});
findViewById(R.id.open_second_activity_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout 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:id="#+id/rootlayout_motionlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d80"
app:layoutDescription="#xml/activity_main_scene"
tools:context=".MainActivity">
<!--
damn overlay!
https://stackoverflow.com/questions/52996035/motionlayout-using-crossfade-altsrc-appears-on-top-of-src-original-image-does
-->
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="#+id/about_imagefilterview"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="#drawable/ic_about_icon_normal_filled"
app:altSrc="#drawable/ic_about_icon_normal_empty"
app:layout_constraintBottom_toTopOf="#id/mainactivity_guidline_about_icon_bottom"
app:layout_constraintDimensionRatio="1"
app:layout_constraintEnd_toStartOf="#id/mainactivity_guidline_about_icon_right_end"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toEndOf="#id/mainactivity_guidline_about_icon_left_end"
app:layout_constraintTop_toBottomOf="#id/mainactivity_guidline_about_icon_top"
app:overlay="false" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mainactivity_guidline_about_icon_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.038" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mainactivity_guidline_about_icon_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.079" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mainactivity_guidline_about_icon_right_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.95" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mainactivity_guidline_about_icon_left_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.05" />
<Button
android:id="#+id/open_second_activity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to Second"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.motion.widget.MotionLayout>
activity_main_scene.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
android:id="#+id/mainactivity_transition_about_icon_1"
motion:constraintSetEnd="#+id/mainactivity_constraintset_state2"
motion:constraintSetStart="#id/mainactivity_constraintset_state1"
motion:duration="500" />
<Transition
android:id="#+id/mainactivity_transition_about_icon_2"
motion:constraintSetEnd="#+id/mainactivity_constraintset_state1"
motion:constraintSetStart="#id/mainactivity_constraintset_state2"
motion:duration="500" />
<!-- ===================================== CONSTRAINTSETS ===================================== -->
<ConstraintSet android:id="#+id/mainactivity_constraintset_state1">
<Constraint
android:id="#+id/about_imagefilterview"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintBottom_toTopOf="#id/mainactivity_guidline_about_icon_bottom"
motion:layout_constraintDimensionRatio="1"
motion:layout_constraintEnd_toStartOf="#id/mainactivity_guidline_about_icon_right_end"
motion:layout_constraintHorizontal_bias="1"
motion:layout_constraintStart_toEndOf="#id/mainactivity_guidline_about_icon_left_end"
motion:layout_constraintTop_toBottomOf="#id/mainactivity_guidline_about_icon_top">
<CustomAttribute
motion:attributeName="crossfade"
motion:customFloatValue="0" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="#+id/mainactivity_constraintset_state2">
<Constraint
android:id="#+id/about_imagefilterview"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintBottom_toTopOf="#id/mainactivity_guidline_about_icon_bottom"
motion:layout_constraintDimensionRatio="1"
motion:layout_constraintEnd_toStartOf="#id/mainactivity_guidline_about_icon_right_end"
motion:layout_constraintHorizontal_bias="0"
motion:layout_constraintStart_toEndOf="#id/mainactivity_guidline_about_icon_left_end"
motion:layout_constraintTop_toBottomOf="#id/mainactivity_guidline_about_icon_top">
<CustomAttribute
motion:attributeName="crossfade"
motion:customFloatValue="1" />
</Constraint>
</ConstraintSet>
</MotionScene>
SecondActivity.Java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class SecondActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="#b40"
tools:context=".SecondActivity">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:src="#drawable/ic_about_icon_normal_empty"
app:layout_constraintBottom_toTopOf="#id/secondactivity_imageview_bottom"
app:layout_constraintDimensionRatio="1"
app:layout_constraintEnd_toStartOf="#id/secondactivity_imageview_right_end"
app:layout_constraintStart_toEndOf="#id/secondactivity_imageview_left_end"
app:layout_constraintTop_toBottomOf="#id/secondactivity_imageview_top" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/secondactivity_imageview_left_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.40" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/secondactivity_imageview_right_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.60" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/secondactivity_imageview_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.40" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/secondactivity_imageview_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.60" />
</androidx.constraintlayout.widget.ConstraintLayout>
Related
Hello i'm stcuk by a little problem,
I want to add a new CardView with same set of the first CardView underneath the first Cardview only when i click on my button and this action can be repetable endlessly.
Because i'm beginner in android and i have litterally no idea how to make that.
If anyone can Copy Past this code and help me i will be very happy.
I know the spinner is void but its for after i just want to duplicate this.
my activity :
package com.example.lif.test;
public class testActivity extends AppCompatActivity {
Spinner idSpinnerLance;
EditText idEdtTempsLance;
TextView idTextViewPuissance, textViewTitre;
Button idButtonAdd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
idSpinnerLance = findViewById(R.id.idSpinnerLance);
idEdtTempsLance = findViewById(R.id.idEdtTempsLance);
textViewTitre = findViewById(R.id.textViewTitre);
idTextViewPuissance = findViewById(R.id.idTextViewPuissance);
idButtonAdd = findViewById(R.id.idButtonAdd);
idButtonAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
}
}
and my xml code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".test.testActivity">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="10dp"
android:layout_margin="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ajouter une lance :"
android:textColor="?android:textColorPrimary"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/idSpinnerLance"
android:layout_width="150dp"
android:layout_height="47dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Temps :"
android:textColor="?android:textColorPrimary"
android:textSize="15dp"
android:textStyle="bold" />
<EditText
android:id="#+id/idEdtTempsLance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<Button
android:id="#+id/idButtonAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="add" />
</LinearLayout>
</ScrollView>
thank you
If those CardView will contain different data you can use a RecyclerView and on button click you can add an item in the list and notify the adapter this will add a new item(here item is your CardView created in a different XML file) on screen.
This could be helpful
and this too
I'm a beginner, but I want to learn and I'm developing my first app!!I would also like to use the "toaster" function in the app. Unfortunately no longer works !!
Not only in my app, but no matter where I want to use it. Should I reinstall android studio?
Thank you, Stefan
Hi, no error message! Just not work!!
MainActivity:
package de.havadinagy.toaster_test;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
public void info(View view){
Toast.makeText(this,"Only Toastertest!!" ,Toast.LENGTH_LONG).show();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="243dp"
android:layout_height="172dp"
android:onClick="info"
android:text="ToasterTest"
android:textColor="#color/black"
android:textSize="24sp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
try this
Toast.makeText(requireContext(), "message", Toast.LENGTH_SHORT).show()
do try this
try
public void info(View view){
Toast.makeText(MainActivity.this,"Only Toastertest!!" ,Toast.LENGTH_LONG).show();
}
and change "info"
I have this xml file where there are 4 image views, with one logo at the centre and the other three are just circles with radius greater than the previous one surrounding the logo. I want to display this as an animation until my page gets loaded. In want that the three circles appear one after the other in loop in a sequence. How can I do that ?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<ImageView
android:id="#+id/imageView"
android:layout_width="150dp"
android:layout_height="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/center" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="150dp"
android:layout_height="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/anim1" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="150dp"
android:layout_height="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/anim2" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="150dp"
android:layout_height="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/anim3" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have also attached a picture for a better visualization if needed :
enter image description here
#Srijan,
There are more ways to achieve this.
Please refer to objectAnimator or animation-list drawable for more details.
As a quick answer to your problem, please see the below sample code.
package com.jrh.testanim;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
int count= 0;
int imgArr[] = new int[]{
R.drawable.circle1,
R.drawable.circle2,
R.drawable.circle3,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView imageView = (ImageView) findViewById(R.id.animation_imageview);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
imageView.setImageResource(imgArr[count]);
handler.postDelayed(this, 500);
count++;
if (count > 2) {
count = 0;
}
}
}, 500);
}
}
Please check this and mark accepted, if it solves your problem.
Thanks
JRH
I have a fragment layout that is a part of a PageViewer.
The fragment has 2 RecyclerViews - one on the top of the layout which is horizontal, the other one at the bottom which is vertical.
Here is my XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_margin="7dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/fragment_marketplace_marketplace_title"
android:textSize="30sp"
android:textStyle="bold" />
<SearchView
android:id="#+id/fragment_marketplace_searchview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint="Search..."
app:iconifiedByDefault="false"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="15dp"
android:text="#string/fragment_marketplace_discover_products_from_myverte"
android:textSize="17sp"
android:textStyle="bold" />
<android.support.v7.widget.RecyclerView
android:id="#+id/fragment_marketplace_brands_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
tools:listitem="#layout/fragment_marketplace_vendor_row_item" />
<android.support.v4.widget.NestedScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginLeft="14dp"
android:background="#color/very_light_grey"
android:paddingTop="15dp"
android:text="#string/fragment_marketplace_featured_products"
android:textSize="17sp"
android:textStyle="bold" />
<android.support.v7.widget.RecyclerView
android:id="#+id/fragment_marketplace_products_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/very_light_grey"
tools:listitem="#layout/fragment_marketplace_products_row_item" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
1) When scrolling left/right the scrolling sometimes gets stuck and not responsive. Why does this happen?
2) How do I make the view shows some part of the next views in the list, so it will make the filling of an actual scrollable list and not just a stale image?
edit -
here is my row item xml -
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="10dp">
<ImageView
android:id="#+id/vendorImageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
edit -
my recyclerview initing -
private void initViews(View view) {
gson = new Gson();
miniVendorModelList = new ArrayList<>();
miniProductModelList = new ArrayList<>();
searchView = view.findViewById(R.id.fragment_marketplace_searchview);
Drawable drawable = getResources().getDrawable(R.drawable.search_widget_very_light_grey_background);
searchView.setBackground(drawable);
//adapters
vendorsAdapter = new VendorAdapter(miniVendorModelList);
productsAdapter = new ProductsAdapter(miniProductModelList, getContext());
//lists
vendorsList = view.findViewById(R.id.fragment_marketplace_brands_recycler_view);
productsList = view.findViewById(R.id.fragment_marketplace_products_recycler_view);
vendorsList.setNestedScrollingEnabled(false);
productsList.setNestedScrollingEnabled(false);
//brands recycler
vendorsList.setHasFixedSize(true);
vendorsList.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL, false));
vendorsList.setAdapter(vendorsAdapter);
//products recycler
productsList.setLayoutManager(new GridLayoutManager(getContext(), 2));
productsList.setHasFixedSize(true);
productsList.setAdapter(productsAdapter);
}
my adapter -
package com.twoverte.adapters;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.twoverte.R;
import com.twoverte.adapters.holder.VendorsHolder;
import com.twoverte.models.Vendor.MiniVendorModel;
import java.util.ArrayList;
public class VendorAdapter extends RecyclerView.Adapter<VendorsHolder> {
private ArrayList<MiniVendorModel> miniVendorModels;
public VendorAdapter(ArrayList<MiniVendorModel> miniVendorModels) {
this.miniVendorModels = miniVendorModels;
}
#NonNull
#Override
public VendorsHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_marketplace_vendor_row_item, viewGroup, false);
return new VendorsHolder(view);
}
#Override
public void onBindViewHolder(#NonNull VendorsHolder vendorsHolder, int i) {
MiniVendorModel model = miniVendorModels.get(i);
Picasso.get().load(model.getImageURL()).memoryPolicy(MemoryPolicy.NO_CACHE).into(vendorsHolder.vendorImageView);
}
#Override
public int getItemCount() {
return miniVendorModels.size();
}
}
How do I make the view shows some part of the next views in the list, so it will make the filling of an actual scrollable list and not just a stale image?
What you can do here is make your layout/fragment_marketplace_vendor_row_item occupy say 80% width also add some padding
update width to 80%
android:layout_width="0dp"
android:layout_weight="0.8"
When scrolling left/right the scrolling sometimes gets stuck and not responsive. Why does this happen?
this might have been answered here
Found a solution for bad scrolling - wrapped the horizontal RV with a NestedScrollView. Works perfectly, I have no idea why. Just trial and error.
If someone knows why this works it would be awesome.
I am doing a project that requires me to change an image in the same form content page with a button onclick or another button method if you have one. I normally program in C# with visual studio and I am not used to the java so I would greatly appreciate it, Thank you.
Here is a sample image changer code
Xml -
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<Button
android:id="#+id/changeBtn"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginStart="151dp"
android:layout_marginLeft="151dp"
android:layout_marginEnd="172dp"
android:layout_marginRight="172dp"
android:layout_marginBottom="4dp"
android:onClick="change"
android:text="Change"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="456dp"
android:layout_height="632dp"
android:scaleType="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/cats01" />
</android.support.constraint.ConstraintLayout>
Main Activity code
public class MainActivity extends AppCompatActivity {
private int i =0;
public void change(View view)
{
ImageView imageView2 = (ImageView)findViewById(R.id.imageView2);
imageView2.setImageResource(R.drawable.cats01); // this function
changes the image
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}