Issue with android studio and radiogroup - java

I'm trying to make a simple app in android studio but running into trouble with layout whenever I place down a RadioGroup. In my first image here I've created a RadioGroupand dragged two RadioButtons into it by dragging them to the radiogroup option on the component tree trying to drop them into the radiogroup on the layout thing is impossible as the radiogroup is completely invisible on it.
I drag a button below it, lining it up with the center, and the box that shows where the buttons going to go shows it being below the radiogroup. But once I release the mouse button, the button im attempting to place ends up here.
I've been fighting with android studio for a while now but if I get the button even remotely close to the RadioGroup it gets catapulted up the screen, and I don't have enough room if I place the button way down low for my other elements.
tl;dr
radiogroups are catapulting any elements underneath them above them. its probably a layout or gravity issue or something like that. but I don't know how to fix it and would like my buttons to not be underneath all the other elements kthx.

I'm not sure what is causing your issue, because you aren't providing enough information. But If you want the button to appear under your radio group, then in your xml file, give your radio group an id android:id="#+id/radioGroup" and in your button add android:layout_below="#id/radioGroup".

Try to android:layout_below="#+id/radioGroup" in your button.As your are using Relative Layout by default it takes you top while dragging.Here is full Button view.
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:id="#+id/button"
android:layout_below="#+id/yourRadioGroupId"
android:layout_centerHorizontal="true" />

Related

Placing an image in button but it does not show image

I created a button and I used android:background="#drawable/background" to change the image however it only displays the default design of a button (purple). How do I set it to the image I have saved in my drawable folder?
I know there is Image Button but I wanted to write a text on the button, but there is no feature where I can write a text on top if I used Image Button
As you have mentioned, you can't put a text if you have used ImageButton.
As far as I understood, you want to have view which has a text on above of image and image on bottom of the text.
If you use android:background feature on Button, button's background will be your drawable image and it won't be as you have expected.
If you are going to use Button for sure, you can use android:drawableBottom feature to show your drawable image on below of your text. And you can basically add button text by using android:text feature.
My advice to you, you should use TextView instead of Button for that case. Because if you do it with the Button as I have mentioned above, your button will have background and you can make transparent background for your button by using below code.
<Button
android:id="#+id/buttonMoreTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawableBottom="#drawable/ic_baseline_home_24"
android:text="#string/app_name"
android:textColor="#color/black" />
This code will make your Button has a transparent background.
android:background="#android:color/transparent"
But this is a little bit hacky solution. If it won't have background and if you do not have to use Button in your case for sure, you can use TextView for that and basically to show text and drawable on bottom, you can code your TextView basically as below.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
app:drawableBottomCompat="#drawable/ic_baseline_home_24" />
Note: These are very simple xml examples to solve your main problem about showing image on bottom of your text, in same view. If you need anything more, let me know and I would be glad to help.

Is it possible to make a TextView marquee stop and reverse when the whole text has been shown?

I have a TextView that represents the title of the current fragment and is located in the toolbar. When the user uses a big font size, the title sometimes becomes too long to be displayed completely. Hence I want to have it scroll to the right until the whole text has been shown, then stop for two seconds and then scroll back to the left where it stops as well. This should be repeated forever.
I have tried using marquee to accomplish this (see below), but there doesn't seem to be any option to make marquee stop scrolling, let alone dynamically reverse it. If there are any alternatives to marquee that have this option, I'd be happy to use them as well.
Currently the TextView looks like this:
<TextView
android:id="#+id/title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"/>
there is no such option, you have to end with custom solution. some sample with custom initialization can be found here (speeds up marquee, you have to modify code)

Android Studio viewFlipper Crashing App

I'm making an application. I have succeeded in creating a viewFlipper with:
android:flipInterval="5000"
android:autoStart="true"
I've also made two buttons, next and previous, with:
android:clickable="true"
android:onClick="onClick"
I want each button to affect the ViewFlipper, as in when the next button is pressed, the next image is displayed. And, when the previous button is pressed, the previous image is displayed.
What do I need to add to the XML file and what do I need to add to the MainActivity class? Everything I've tried up until now either prevents the app opening or crashes the app when the button is pressed.
Any and all help is greatly appreciated.

Android Studio Layout Auto Alignment

I am new to Android Studio, and no matter what I do whenever I add something such as a textview or button to it, I cannot make it the size I want it to. It always auto aligns itself to the sides or top. When I want to make a square it doesn't allow me to do it. It never allows me to put my button or textview where I want it to. How do I make it so I can place my stuff anywhere I want and whatever size I choose it to be?
You are probably using linear layout,You can use relative layout instead for start, although if you want to put a lot of buttons its getting harder to work with relative layout and linear layout is more organized go to you'r xml and there edit the in the first line where it says <LinearLayout... to <RelativeLayout> and don't forget to do the same at closing,I recommend you to watch a video on youtube on how to work with linear layouts.
In RelativeLayout, it enable the attributes like alignParentRight="true/false" for exact right position and so on...
layout_below="#id/tool/viewID_below_you_want_to_put" and same for other side
so you can use it
For Example,
<RelativeLayout
...>
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_toRightOf="#id/txt1"
android:alignParentRight="true"
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
which will make your textview in left and then button in right of textview
If you want to set it in center tou can set gravity="center | center_vertical | center_horizontal"
also you can set size as you want in width or height like
android:layout_width="50dp"

2D scrolling View for Images and Buttons (on smaller screens)

How can you create larger views than the screen real-estate in Android?
I am trying to recreate a view from my iOS project in Android. The view consists of a first column of static images and then a 20x13 grid of buttons (yes that's 260 in total!) which will generate another activity when clicked:
Each button throws out an integer and there is a daily background image change.
The problem for phones is screen real-estate. Fitting everything on one screen makes the buttons too small to touch properly. In the iPhone app I created bigger buttons set offscreen within a ScrollView that the user could then scroll to. To my knowledge Android does not do a 2d version of ScrollView. I have tried to use gridview dynamically, for example:
However, the dynamic buttons generated need to go VERTICALLY, they are too small to press on smaller screens AND it only scrolls in one direction.
I have also been thinking about 14 Vertical Linear/RelativeLayouts but again I am limited to screen dimensions which will make the buttons too small.
I did implement code from this link which works perfectly well. You create a custom scrollView and then insert it within your XML file:
<RelativeLayout
android:id="#+id/scene_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawingCacheQuality="low"
android:orientation="horizontal" >
<com.example.yourappname.TwoDScrollView
android:id="#+id/scene_scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawingCacheQuality="low" >
</com.example.yourappname.TwoDScrollView>
</RelativeLayout>
You can then put your items in a layout and be sure to sort the width/height parameters to what you need - match_parent will fix your layout to the screen.

Categories