So, I wanted to make a scroll-able worldmap with clickable countries. So when I found out there was a thing like VectorDrawables, I decided to give these a try.
Next thing I did was making a VectorDrawable xml file out of a SVG and tried to put it in my ImageView. While searching for some info, I found out that there were 101 ways to do this, and none of them worked for me...
The interesting thing is that, when I add "android:src="#raw/worldmap" in the ImageView in my activity.xml, the map shows up in the preview, but whenever I try to run the app, it crashes.
<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:orientation="vertical"
android:id="#+id/activity_show_hint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.bert.myapplication.ShowHintActivity"
android:weightSum="1">
<ImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:scaleType="center"
android:src="#raw/worldmap">
</ImageView>
</LinearLayout>
First, move your VectorDrawable to Drawable folder (not in raw). and then, add this line in your Gradle file :
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
And finally, in your imageView, change to this;
<ImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:scaleType="center"
app:srcCompat="#drawable/worldmap">
</ImageView>
Related
As you can see on the upper image, there are align options "to RightOf=button", "below=button" when you drag something, but when I drag something nothing like that is shown. Can anyone help me fix that?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:id="#+id/text_witaj_uzytkowniku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/witaj_uzytkowniku" />
</RelativeLayout>
Honestly, I prefer to use ConstraintLayout as the root. I believe it is much easier to use with the drag and drop tool.
When using it make sure that all objects are connected to each other(or the parent) at least once vertically and once horizontally.
How this looks in the code:
<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">
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="#+id/textView9"
app:layout_constraintTop_toBottomOf="#+id/textView9" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can also adjust the distances using the side panel.
To use the layout you just need to type Constraint layout in the Pallete and drag it (if it is not installed, there will be a download)
Set position of your textview then try to add another view by dragging
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:id="#+id/text_witaj_uzytkowniku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop ="true"
android:layout_alignParentLeft="true"
android:text="#string/witaj_uzytkowniku" />
</RelativeLayout>
I think instead of Relativelayout, you should use the CoordinatorLayout.
And if you continue with Relativelayout then go to file invalidate and restart your Android studio if this is cache related issue then resolved it.
Use Coordinator Layout to work. RelativeLayout is more of coding layout..
I have a horizontalScrollView containing 1 image that is used as the background. This image can be scrolled left to right. I would like to place other imageviews on to the background image but not have them scroll with it. At the moment if I place another imageview on top of this, when I scroll the image comes as well.
The scroll view at far left:
The scroll view at far right:
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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/activity_rear_gunner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusable="true"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner">
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent" app:srcCompat="#drawable/background_scroll_2"
android:id="#+id/scrollView" android:layout_centerVertical="true"
android:scaleType="centerCrop"
/>
</HorizontalScrollView>
<RelativeLayout
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/item_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusable="true"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner">
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="#drawable/placeholder_bomber"
android:id="#+id/enemy" android:layout_centerVertical="true"
/>
</RelativeLayout>
Very new to using layouts in android. Hope I made my problem clear if not I do apologize and will try to clarify if asked. I know this could have something to do with what layouts I am using and the child and parents of them layouts but like I said new to this.
The HorizontalSCrollView can have only one child, but that child could be another layout, so you can add as many ImageView you want.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="3000dp"
android:layout_height="match_parent"
android:background="#a30"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#aa0"
/>
</RelativeLayout>
</HorizontalScrollView>
How to set the tab background color dynamically? I had tried to get the app:tabBackground="#drawable/tab_background" in the java code but I can't find please help me out friends I am using design library by google I had tried the custom view in the tab layout it worked but the gap is coming in between the tabs
My code
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.first_tab), true);
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.second_tab));
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.third_tab));
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.fourth_tab));
icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.five_tab));
My Layout for custom tab
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<FrameLayout
android:id="#+id/first_ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/first_tab_drawable">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:src="#drawable/love_home" />
</FrameLayout>
</FrameLayout>
im making a launcher app. in the tutorial it uses a Sliding Drawer which deprecated in Api 17. what could i use instead of this? i tried using the Slideup Panel from one of the posts on here link Below to the gitHub below
gitHubLinkhttps://github.com/umano/AndroidSlidingUpPanel
. but it wont allow me to use it in the way i want. i want the apps to appear in the drawer not in the main content. for some reason the second view only allows me to create a Text view which is for the handle to slide it up. any advice on what other methods i could implment to do the same job. it must slide up from the bottom. thanks for all the help
Ok guys Sussed it. Using The GitHub I posted in the question. what it did is because im aloud as many layouts as i like but only 2 children. i used a relative layout as my first layout with a gridView for my homescreen apps inside and closed it off. then i used anther Relative Layout Below with a textview inside then another Relative layout set with 80dp Padding at the top (the Size of my Text Handle) inside this one i had another gridview for my apps and closed it all off.
the Xml for it looks like this
<RelativeLayout 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" tools:context=".MainActivity"
android:id="#+id/Mainlayout"
>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="80sp"
sothree:umanoShadowHeight="4dp"
sothree:umanoDragView ="#+id/dragView"
sothree:umanoScrollableView="#+id/list"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content1"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:clickable="true"
>
</GridView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/handle"
android:text="b"
android:textSize="80sp"
android:textColor="#17ff1c"
android:gravity="center|top"
android:clickable="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="80sp"
android:id="#+id/dragView"
android:clickable="true"
android:focusable="false">
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="80sp"
android:id="#+id/content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:gravity="center"
>
</GridView>
</RelativeLayout>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
I am building an app that uses this library:https://github.com/umano/AndroidSlidingUpPanel to create a panel that slides on from the bottom of the screen when a user clicks an item in a listview.
However i dont want the slide up panel to take up the entire screen. I need there to be a gap at the top, between the panel and the action bar, of exactly 80dp.
I have tried everything i can think of (putting a spacer there with a transparant background, using layoutParams (gives error), etc). But nothing seems to work.
If someone could give me some suggestions as to what i could try next, i would much appreciate it.
The xml layouts are below.
Thanks for your time.
Corey
<com.bacon.corey.audiotimeshift.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="68dp"
sothree:shadowHeight="4dp"
sothree:overlay="true">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:id="#+id/fabbutton"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
app:colour="#color/holo_red_light"
app:drawable="#drawable/ic_content_new"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:textSize="16sp"
android:id="#+id/slideUpPanel"
android:background="#android:color/transparent"
>
<fragment android:name="com.bacon.corey.audiotimeshift.PlayFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_play"
/>
</FrameLayout>
</com.bacon.corey.audiotimeshift.SlidingUpPanelLayout>
What about wrapping your SlidingUpPanelLayout in another layout, say FrameLayout and adding some good old paddingTop to the latter?
I have found a workaround. Draw the background of the pane transparent and put a padding top, but first the library must be modified like it's written here:
https://github.com/umano/AndroidSlidingUpPanel/issues/4
Hope this helps somebody in the future :)