I am having a problem with stucked canvas where the user should add he's own image then can cover "surround" it with color the problem is that I can't marge relative layout with canvas I tried but I can't , when I move my finger on the screen the Canvas should change the color
but when I add it to layout I can't do that the color won't change and the cursor Is not moving too , So The Canvas is not activated here's where I set the layout as contentview then adding the canvas to it the on touch is outside both classes below layout Class
and above Surface Class
setContentView(R.layout.MyLayOutName);
canvaslayout = (RelativeLayout) findViewById(R.id.MyLayOutId);
//extending the surfaceview from another class inside layout class
View = new SurfaceView(this);
canvaslayout.addView(ourView);
and this is the layout xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout android:id="#+id/drawingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<SurfaceView
android:id="#+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
The full code is
here
Related
I have a button in my MainActivity that opens FragmentA. FragmentA covers the whole screen, but I still see the button from MainActivity, and I can still click on it.
I've tried using clickable in my fragment layout but it's not working
MainActivty
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener {
val fragmentManager = this#MainActivity.supportFragmentManager
fragmentManager.beginTransaction()
.add(R.id.fragment_container, AFragment())
.addToBackStack(null)
.commit()
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/fragment_container">
<Button
android:text="Button Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</android.support.constraint.ConstraintLayout>
fragment_a.xml
<?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:clickable="true"
android:focusable="true">
android:background="#color/colorPrimary"
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="A"/>
</LinearLayout>
This is happening because you placed your Button inside of the ConstraintLayout you're using as the container of your Fragment.
When you add a fragment into a container like what you're doing, it's simply adding it in the same manner as if it was a View.
Therefore, if you add a Fragment into a ConstraintLayout that already possesses a Button as a child, the Fragment will be shown alongside the Button due to ConstraintLayout allowing for overlapping Views.
This is also why, if your container was a LinearLayout, then adding a Fragment will place the fragment underneath your Button instead.
So, with that in mind, the solution would be to handle it as if they were Views.
If you added a View into a layout and you have another View overlapping, how would you get rid of it?
The most common solution would be to set the Button's visibility to INVISIBLE or GONE when the Fragment is added.
Another solution might be to raise the elevation of the Fragment, so it's now higher than your Button.
Of course, you may also remove the button from the Container and place it inside a Fragment too.
This way, you can use the replace() method in a FragmentManager to replace the Fragment containing your Button with the Fragment you want to show.
I have a viewPager with infinite loop, but i want to set a border to highlight the current image.
In my main activity i've the adapterPageAdapter and the custom ViewPager (that is clickable).
I think that is easy, but i need help.
Something like this:
Thanks
> Place image view inside another layout set the background color of
> parent layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp">
<ImageView
android:id="#+id/imageViewImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:foregroundGravity="center_horizontal"/>
</RelativeLayout>
> inside PagerAdapter instantiateItem method when you are setting bitmap
> to imageView, also set backgroud color to layout.
final RelativeLayout border = (RelativeLayout) view.findViewById(R.id.border);
border.setBackgroundColor(Color.RED);
I am trying to build a slider that slides on top of my current view in Android. I built the slider using the SlideUp library found here https://github.com/mancj/SlideUp-Android. The slider is taking the inner RelativeLayout as a view source. When I pull up the slider it ends up behind the CardView. I've looked through all the methods in the library and there isn't one that allows you to move the slider to the foreground. I've also tried to bring the slider view to foreground with .bringToFront() method. Moving the slider view before the CardView in the .xml file does nothing either. Is there a good way to bring the slider to foreground... or the CardView in the background? (without hiding the CardView)
JAVA
//code to build slider
View slideView = findViewById(R.id.slider);
//tried putting slideView.bringToFront() here before passing it to the object but that did nothing
SlideUp slideUp = new SlideUpBuilder(slideView)
.withStartState(SlideUp.State.HIDDEN)
.withStartGravity(Gravity.BOTTOM)
.build();
//code to bring up slider. View "share" exists, it's just irrelevant so I didn't include in the .xml file
buttonView.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//tried putting slideView.bringToFront() here as well
slideUp.toggle(); //toggles slider up/down
}
});
XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="#color/background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="60dp">
</android.support.v7.widget.CardView>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/slider"
android:background="#color/primary">
</RelativeLayout>
</RelativeLayout>
I figured it out. I found out I can add android:elevation="2dp" for the slider and 0dp for the CardView
List Fragment height is not working properly, it only shows 1st row of list, other rows of list dont show. I used wrap content for height but not working. If i run Fragment directly it shows all rows but if i add fragment in my main activity its show single row. Other rows show if i change height of fragment manually like layout_height="100dp";. I want fragment height to be dynamic. This my main activity xml code:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/app_bar_welcome" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.app.Fragments.SpecialListFragment"
android:id="#+id/fragment3"
tools:layout="#layout/fragment_special_list" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#efefef">
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
If i change height of fragment to 100dp:
fragment list height 100dp
If i wrap content fragment:
wrap content height of list fragment
I have a custom view that looks a little like a speedometer.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:slider="http://schemas.android.com/apk/res-auto"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.mysite.view.SeekBar_Speedometer
android:id="#+id/slider"
slider:fill_clockwise_color="#color/lightgrey"
slider:fill_anticlockwise_color="#color/blue"
slider:fill_handle_color="#color/green"
slider:fill_handle_width="3"
slider:angle_start="120"
slider:angle_end="60"
slider:fill_start_angle="120"
slider:score_min="0"
slider:score_max="300"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I would like to add an edittext to the center of the speedometer.
Just as you can draw text to the canvas can I add an edittext in the same way from inside my view? I don't think so!
Question is, how do I go about adding this edittext to my custom view?
inside your custom view class you can do:
EditText edit = new EditText(context);
addView( edit );
To do this your custom view must extends a ViewGroup (LinearLayout, RelativeLayout, ecc..)