is possible to make a button shape like a cross? - android-studio

is possible to have a single button that has a shape of a cross and that it is clickable only in the visible part?
defining curves with coordinates or setting an image with this cross and somehow setting that where the image is transparent, it must not be clickable ..
if yes, with witch method?
I tried to search online but apart from the radus (which in this case I don't need), I didn't find any documentation

yes you can add your button as ImageButton and put your shap in that button
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:scaleType="fitXY"
android:background="#color/transparent"
android:src="#drawable/ic_close_image"/>

Related

Problems with the color Vector Asset in Floating Action Button

So, guys.
I created an Asset Vector to use in my Fluting Action Button(Asset Add or Plus), in white color. When I add it to the FAB, it turns black and I can't change it.
Where can I make the change?
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:fabSize="normal"
app:rippleColor="#color/white"
app:srcCompat="#drawable/ic_confirmar_24"
/>
enter image description here
Just add app:tint="#color/white" in your FloatingActionButton.

Is there a good way to make a button in Android do different things depending on if you click on the left half or right half of the button?

In an android app I am making, I would like to make a button that does different things depending on whether the user presses the left half of the button or the right half of the button. Right now I'm trying to figure out what would be the best way to accomplish this.
Some other specific requirements:
1. I'm planning on using the button 1 to 4 times per Activity.
2. It would be very helpful if I could be able to rotate the button (e.g. 90 degrees, 180 degrees so it's upside-down)
One idea I have had is putting two buttons side by side and putting a text-view on the top to make it look like one button. I found this doesn't really work well. It requires lots of effort to get it to show up properly and gets messed up when even small changes are made.
Another idea I had was making a custom button by extending the view class. Problem is I have no experience doing something like that and most of the tutorials I've seen use it to make paint programs.
What would be the best way to create something like this??
Edit: When I say rotate the button, I don't mean that the button needs to rotate when clicked or when some other action is performed. Just that it is facing in the direction I need it to be when the app loads. Also it only needs to be facing in the standard 4 directions (i.e. Down, Up, Left, Right). Sorry I wasn't more clear on that.
i created the first approach using framelayout as follow:
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="70dp"
android:onClick="rotate">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView2">
<Button
android:id="#+id/button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorPrimary" />
<Button
android:id="#+id/button2"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorAccent" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="Button text"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textColor="#android:color/white" />
</FrameLayout>
for rotating any view create your anim.xml file inside anim folder in res
right click on res -> new android res dir-> choose anim then create anim file right click on anim folder you just created and new anim res file and the past the code in side it , this will rotate your framelayout in this certain code by 180 degeree
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<rotate
android:duration="500"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="180" />
</set>
use it as follow on kotlin
fun rotate(view: View) {
val rotate = AnimationUtils.loadAnimation(
applicationContext,
R.anim.rotate
)
frame.startAnimation(rotate)
}

RealPlayer like Android app layout

I am new to Android and I am trying to design my Android application like the interface of the Android RealPlayer but I have no idea how!
What I exactly want to design is: Break the page into 4 equal grid-like sections such that the whole page is covered and no extra empty space is left at the end of the page (exactly like the RealPlayer interface).
<?xml version="l.0" encoding="utf—8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android“
android:id=“#+id/gridview“
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_weight="l.0"
android:columnWidth="90dp"
android:horizontalSpacing="l0dp"
android:numColumns="2"
android:orientation="horizontal"
android:paddingTop="50dp"
android:stretchMode=“columnWidth"
android:verticalSpacing="l0dp" >
</GridView>
I have tried manipulating GridView attributes but it seems that it is not possible only using GridView elements. I hope my problem statement is clear enough! Can somebody give me a hint on how to do that?
I have found out that it is possible using buttons of different sizes!

what element type and layout for should I use for app landing page navigation buttons?

I'm pretty new to Android Development, i'm following some Youtube tutorials currently. I'd like to create a basic mobile tourist application, but i'm stuck as to how to create the main menu layout.
Each Favorite 1 - 3, and Options 1 - 9 should be icons. (I'm not sure which form element should be used for this).
QuestionHow can I create the favorite, and option icons in the layout.xml file, what element is best suited, and what layout(s) should I use?
In HTML, i'd create a table with 3 columns, 4 rows and set the table width and height to be 100%, and make the td valign and align central.
Here you could make horizontal linearLayouts of vertical LineraLayouts of Image+TextView pairs.
The second range linear layouts would have
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
Inside second range layouts you could use for image and text/view:
...for images:
android:layout_width="match_parent"
android:layout_weight="3"
android:layout_height="0dp"
... for texts
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
And the screen is nicely divided.

Where is a reference to the android XML UI layout?

I am looking for a spec or reference of all the possible options for the various XML layout attribute settings that typically come with an android UI. Google seem to be good at burying it. This is similar to this question but remains in-effectively answered.
Such as what are my options available to me for the TextView layout_width definition ? There must be a complete definition published ... somehwere....
layout_* attributes aren't directly part of the view they appear on, which is why you won't find them in TextView's documentation. (TextView is not a ViewGroup.) They are arguments to the parent view, also known as LayoutParams. Take a look at the "Known Subclasses" sections at the top of the linked page for a list of them. They're instructions about how a ViewGroup should arrange each child view, and each parent type can recognize different ones depending on what kinds of layout options it supports.
For example, LinearLayout.LayoutParams supports the android:layout_weight parameter. Children of a LinearLayout can specify weight to request a proportion of the remaining space after all children have been measured. You can give equal weight to two sibling TextViews with a base width of 0 to give them each half of the available space within the parent.
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello" />
<TextView android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="World" />
</LinearLayout>
Normally developer.android.com is your site. Maybe this helps:
http://developer.android.com/reference/android/view/View.html
If you use Eclipse, then the autocomplete suggestions may help you as well in adding the right parameter.
...and the options you have for layout_width are
wrap_content (as large as the content of the View)
fill_parent (extends to the whole size - width or height - of its parent)
Layout parameters are pretty well described in the documentation for ViewGroup.LayoutParams and its subclasses. For the truly strong of heart, you can always browse the source for attr.xml.

Resources