where can I add include in my xml file? - android

I'm trying to add a toolbar in my xml files.
So I made toolbar.xml and I need to include it in upload.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_upload"
android:layout_width="match_parent"
android:padding="10dp"
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.sk.mf.Upload"
android:background="#fff">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageToUpload"
android:layout_gravity="center_horizontal"
android:layout_width="150dp"
android:layout_height="150dp" />
<EditText
android:id="#+id/etUploadName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/bUploadImage"
android:text="Upload Image"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
the problem is, anywhere I place it I had error like:
scrollview can host only one direct child (inside scrollview)
multiple root tags (after scrollview)
...
my question here is, where and how can I put the code below in the xml above?
<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">
<include android:id="#+id/toolbar" layout="#layout/toolbar"></include>
</RelativeLayout>

try this : wrap your layout in LinearLayout and the toolbar tag
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"></include>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_upload"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:padding="10dp"
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.sk.mf.Upload">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageToUpload"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal" />
<EditText
android:id="#+id/etUploadName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/bUploadImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Upload Image" />
</LinearLayout>
</ScrollView>
</LinearLayout>

Related

Android: SwipeRefreshLayout not working on match_parent

The problem is: when SwipeRefreshLayout have android:layout_height="match_parent" - nothing is showed on layout, when its set on something like 200dp it shows listview and refresh works. Listview is populated by custom adapter with rest api.
match_parent
200dp
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Swipelayout_for_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.darek.playerandroid.PlaylistsFragment">
<ListView
android:id="#+id/lvPlaylists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"></ListView>
</android.support.v4.widget.SwipeRefreshLayout>
Update with content_dashboard xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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/content_dashboard"
android:layout_width="match_parent"
android:scrollbars="none"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.darek.playerandroid.Dashboard"
tools:showIn="#layout/app_bar_dashboard"
android:background="#color/colorBackground">
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</ScrollView>
app_bar_dashboard
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="com.example.darek.playerandroid.Dashboard">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_dashboard"
android:id="#+id/include" />
<android.support.design.widget.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:srcCompat="#drawable/ic_add_white_24dp"
android:visibility="invisible" />
</android.support.design.widget.CoordinatorLayout>
playlist_list_item
<?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"
android:orientation="vertical" android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_nosub"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/imgSub"
android:background="#color/colorBackground"
android:scaleType="fitCenter"
android:layout_alignBottom="#+id/textViewPlaylistName"
android:adjustViewBounds="true"
android:cropToPadding="true" />
<TextView
android:text="Playlist name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textViewPlaylistName"
android:textSize="24sp"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_marginLeft="#dimen/activity_vertical_margin" />
</RelativeLayout>
Here is my working code:
<LinearLayout 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:background="#color/backgroundColor"
android:orientation="vertical"
android:paddingEnd="#dimen/normal_space_between_view_in_home"
android:paddingStart="#dimen/normal_space_between_view_in_home"
android:weightSum="1"
tools:context=".activities.DashboardActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ListView
android:id="#+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="#string/no_data_available"
android:visibility="gone" />
</LinearLayout>
And in the fragment:
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout);

Floating Action Button background graphic not showing (android)

I am attempting to put a FAB on a fragment. The problem is that the background graphic (it is a plus sign) is not showing up in the circle, it just looks like a solid circle of color at the bottom. Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
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:gravity="center_horizontal"
tools:context=".SMS2EmailActivity"
android:background="#drawable/backgroundgradient">
<include layout="#layout/contact_content" />
<android.support.design.widget.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:srcCompat="#drawable/plus_circle"
android:tint="#color/tint"
app:elevation="4dp"/>
</android.support.design.widget.CoordinatorLayout>
and the included file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 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:background="#drawable/backgroundgradient"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvInstructions"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add"
android:id="#+id/btnAdd"
android:layout_below="#id/tvInstructions"
/>
<LinearLayout
android:id="#+id/layoutEmailContactEXLVHeader"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="vertical"
android:layout_marginRight="0px"
android:layout_below="#id/btnAdd">
</LinearLayout>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/elvEmailContact"
android:background="#ffffff"
android:cacheColorHint="#00000000"
android:fadeScrollbars="true"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideInset"
android:layout_below="#+id/layoutEmailContactEXLVHeader"
android:scrollbarTrackVertical="#drawable/track"
android:divider="#color/black"
android:dividerHeight="1dp"
>
</ExpandableListView>
What am I doing wrong?
I needed to add:
android:src="#drawable/plus_circle
to the FAB layout.

Android HorizontalScrollView nesting HorizontalScrollView

I want to have a HorizontalScrollView containing a HorizontalScrollView.
This is my current Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
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: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.erik.playground.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:clipChildren="false"
android:nestedScrollingEnabled="true"
android:layout_marginTop="40dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_height="20dp"
app:cardElevation="9dp"
android:layout_width="500dp"/>
<HorizontalScrollView
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:layout_height="20dp"
app:cardElevation="9dp"
android:layout_width="600dp"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
Right now the inner HorizontalScrollView does not scroll and only the outer one scrolls.
Is there a possibility to make that work?

Why My Card View have very long margin

simple question ,
why my Card View have long Margin bettween other list ?
this is my code
card.xml
`
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="150dp"
android:scaleType="fitXY"
android:id="#+id/imagePasar" />
<TextView
style="#style/Base.TextAppearance.AppCompat.Body1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Material Design is stunning!!!"
android:id="#+id/namaPasar" />
</LinearLayout>
</android.support.v7.widget.CardView>
`
and heres the mainLayout that used in the mainActivity
MainLayout
`<?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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="id.web.gosoft.pasarwiki.MainActivity"
tools:showIn="#layout/app_bar_main">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RecViewListPasar"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
It is because of android:scaleType="fitXY". This will scale your image using Fill. Read this guide for more help.

Enable textView above fragment

How can i be able to enable this textView on top of the fragment. I want it to remain static even when fragments change from one another. Iam having no luck enabling it on top. Here is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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: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.skwebviewapp.MainActivity">
<fragment
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/mainFragment"
tools:layout="#layout/fragment_main" />
<TextView
android:layout_width="wrap_content"
android:layout_height="16dp"
android:id="#+id/textView"
android:text="#string/app_name"/>
</LinearLayout>
Try below code,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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: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.skwebviewapp.MainActivity”
android:orientation=“vertical"
android:weightSum=“1.0">
<TextView
android:layout_width="wrap_content"
android:layout_height=“0dp”
android:layout_weight=“0.10"
android:id="#+id/textView"
android:text="#string/app_name”/>
<fragment
android:layout_width="match_parent"
android:layout_height=“0dp"
android:layout_weight=“0.90"
android:id="#+id/mainFragment"
tools:layout="#layout/fragment_main" />
</LinearLayout>
You can try this with RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="16dp"
android:text="#string/app_name" />
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map_view_fargment"
android:name="com.google.android.gms.maps.MapFragment"
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp"
/>
</LinearLayout>

Categories

Resources