Android studio, Why does a button not stay in place - android

I am currently working on a new app in Android studio. I added a button, but when you try to run the program on a virtual device the button goes to the top left of the screen, like it's not anchored in place. It won't stay where I have put it, saying that this won't work either for a text box. I haven't written any code for the button yet but when I see other people do this they don't need to write code when it will still work. So I don't know whats going on. Also I'm kinda a beginner at android studio but still have a good rough idea.
I am also using a macbook pro (Apple operating system).

Yes thank you.
The final resolution is to put in the java area
app:layout_constraintBottom_toBottomof="parent"
app:layout_constraintLeft_toLeftof="parent"
app:layout_constraintRight_toRightof="parent"
app:layout_constraintTop_toLeftof="parent"
Just in case if anyone is looking for a resolved answer in android studio. Thanks

You need to specify the alignment properties for the Components (Button,TextView,EditText etc..)based on the Layout(Linear ,Relative,Constraint) You are using.
Try these
android:layout_gravity="center"
android:gravity="center"
Know more about Layouts , Alignment in Android and Codelabs Example

I had a similar issue with a TextView I was trying to add. There was a little magnet on the upper left corner I had to click to fix the issue on the Design window.

Related

Android 10: 3-button navigation is obscuring bottom of the screen

I have had feedback from Pixel 3/4 users that the bottom of the screen on this app is cut off, obscuring buttons and possibly other controls that the user requires.
This has only started happening on Android 10. The app contains both Xamarin.Android axml and Xamarin.Forms xaml layouts for the views (the particular page that you are viewing below is Xamarin.Forms).
I don't want to set margins, paddings, gravity or such like on the entire app as obviously that would impact non Android 10/Pixel users. I don't really want to check the operating system version and programatically change those properties as that seems quite hacky and will quickly become unmanageable.
I've looked for something similar to a UseSafeArea property for navigation bars rather than notches but there doesn't seem to be any. Is using WindowInsets the only way to this or has someone else had/solved this issue?
How it looks (controls at bottom are obscured):
How it should look (and does on every other device, the data is different here but it's the view that matters):
I had a similar issue which I solved by removing a few lines of code that were there to fix a bug that has since been fixed in Xamarin Forms.
It directly relates to this forum topic: https://forums.xamarin.com/discussion/87176/windowsoftinputmode-doesnt-work-in-xamarin-forms-android
If these lines exist in your MainActivity.cs, try removing them and see if that works:
Window.SetSoftInputMode(Android.Views.SoftInput.AdjustResize);
Window.SetSoftInputMode(SoftInput.StateHidden);
AndroidBug5497WorkaroundForXamarinAndroid.assistActivity(this);

Drag/Drop feature in Android studio not working

I'm new to android programming The drag/ and drop feature in android studio is not working. I can't drag anything to my phone. Right now my fragment is google map view and i want to add a search bar to the view. It just doesn't drag. When I try to add it in text it says element item not allowed here?
This is my activity_maps.xml file
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:id="#+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment">
<item android:id="#+id/search"
android:title="#string/search_title"
android:icon="#drawable/ic_search"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
</fragment>
the new version of android studio uses 2 xml files for each layout. One (e.g. content_main.xml) embedded in the other one (Activity_main.xml).
you should open the content_*.xml and do the design in it.
hope it helps.
In addition to Hamed's answer I also had to:
File > Invalidate Caches / Restart ...
I'm missing vim.
The drag and drop feature is not working in Android Studio.... I also wasted a lot of time searching...what fixed my problem was to select a Theme for the Activity.
The image below will make things clear.
After updating to the latest version of Android Studio (2.2) I started having this problem.
After some searching and playing around I discovered holding down alt allows my to drag and drop. I had the "hold ALT to drag and drop" option checked under Settings-> Appearance & Behavior > Appearance.
Either I had already selected this option and a fix in Android Studio 2.2 made it so the option applied to dragging and dropping with the palette panel OR this option was recently added and defaulted to checked or a problem happened while upgrading that set it to true.
I have this option set in IntelliJ and have used the android studio palette normally before and am mostly sure I used it without having to hold down alt before so I'm going with option A (and it took me an embarrassing amount of time until I tried holding down alt).
In my case, I was using ConstraintLayout in Android Studio 3.0. Fixed it by using android.support.constraint.ConstraintLayout instead.
Go to your "values" folder
and open the "styles.xml" file.
Replace "Theme.AppCompat.Light.DarkActionBar" under the parent tag with "Base.Theme.AppCompat.Light.DarkActionBar"
I faced this problem also and I simply fixed that by changing the theme to DeviceDefault.Light for the activity.
I also faced the same problem. The culprit was that in my parent
android.support.wearable.view.BoxInsetLayout
tag i was dragging the components directly but when i put
FrameLayout
inside
android.support.wearable.view.BoxInsetLayout
tag and then drag my components to
FrameLayout
it worked .
Hope it will help someone.
I know this is old but not being able to drag elements into the design just happened to me (2/18/18). Restarting Android Studio (3.01) did the trick.
I faced the same problem of not dragging elements in Android Studio 3.1.
Restarting the Android Studio, fixed the problem for me
I figured it out. Even though the design panel is visible as well as the Palette and Component Tree I ALSO need to have app/src/main/res/layout/fragment_main.xml selected over in the Project panel in order for the actual design of the layout to be enabled.
Drag 'n' Drop may not work properly, when you have a LinearLayout, in that condition, the items you drag will try to settle in a specific manner(Horizontal or Vertical), instead try to change your main layout to Relative Layout
Linear Layout --> Relative Layout
I know this is a old issue,none of these were working for me, and it so happened that it wasn't android studio that was giving this problem it was windows. I noticed I couldn't drag anything so clicking and holding any file on the desktop and pressing escape is what fixed it for me.
I resolve this problem by simply rebuild my android studio project.
I was facing the same problem,but then I found the solution .
All you have to do is select the element you want to add(eg. Button) and press "Enter".
The component will be displayed on your screen.
Or you can select the component and right click -> Add to Design
I have did everything in this post, until I've run android studio by just running and not running with "Run As Administrator"(Right Click -> More -> Run As Administrator). I've used to run android studio with "Run As Administrator" and that caused the problem to not drag and drop. Just run Android Studio without "Run As Administrator".
Or try do vice versa and actually "Run As Administrator" if you already just running it without "Run As Administrator".
File>Settings>Appearance and Behavior>Appearance>Theme -> IntelliJ Light
Change your settings to the above path. Then you can drag and drop the views on the design view.
I was also confused with the drag&drop feature. Until I figured out:
After beginning to drag you have to release the mouse button and everything works fine.
Nice feature - a bit unusual though.
I just downloaded Android Studio and ran into this problem.
After clicking random buttons for a few minutes I found out:
There's a magnet icon in the toolbar right above the design view called "Disable Autoconnection to Parent". After I clicked this I was able to move the button wherever.

Eclipse- moves my button labels right

as You can see on the screen shot: all labels on my buttons in Android layout designing are moved right. Of course they are correct when using emulator, but this irritates me during designing layout.
Whan can I do to change this?!
Screenshot
OK I solved it myself: it requires to restart Eclipse, and if that doesn't help: restart computer and Eclipse ;-)

widgets missing from graphical layout palette (android on eclipse)

I'm not sure what happened exactly, but when I started up eclipse, there are no widgets in the graphical layout palette, as in the folders show nothing in them. It has worked before. Is there any way to fix this?
Got the same problem, just enlarge your Graphical Layout and it works.
Switch your computer system language from your country language to English! The widget folders in palette cannot read your country language; only English.
This fixed it for me.
I experienced a similar problem, where some of the widgets such as TextView and EditText were missing from the paleltte.
Here is what I did - from the paleltte, click on the arrow pointing downwards and select "Refresh Preview", here is a picture of what I'm talking about:
right click on palette then select DOCK ON then select left
It will not show if there is not enough space on your screen fr some reason. You need to minimize a window to open up your working space and it will show.
The same thing happened to me.
After trying everything, I changed the theme of the project. And oddly, the widgets reappeared.
The themes can be changed in the top bar of the design window.

"no XML content. go to outline view and add nodes." problem in eclipse (indigo), linux

I've just moved my entire development suite from windows to linux. Huuray.
I have installed the entire android sdk on my laptop, and the ADT works great.
The only problem that I have is the above written text in my main.xml layout window, and I do not know how to view the layout itself. On top of it, I don't see the UI pallet.
I have deleted and reinstalled the entire eclipse\SDK\ADT sevral times, but I just can't get to view my UI pallet.
Did someone encounter this problem? if so, I'd love to hear how you solved it.
Thank you,
dan.
The only problem that I have is the above written text in my main.xml layout window, and I do not know how to view the layout itself.
If you are seeing this message, then there is no layout yet. You can drag something from the tool palette into the drag-and-drop area of the "Graphical Preview" sub-tab, or click on the "main.xml" sub-tab (below the editing area, above the console, in a typical Java perspective tools layout) to work with the raw XML.
On top of it, I don't see the UI pallet.
AFAIK, that is not removable. It will be to the left of the drag-and-drop area in the "Graphical Preview" sub-tab:
If your Eclipse looks substantially different, perhaps posting a screenshot of your own will help us give you more concrete advice.

Categories

Resources