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>
Related
Android Studio does not display a preview of the layout. No errors or warnings are showing. I already try this solution Invalidate Caches/ Restart.
XML File :
<?xml version="1.0" encoding="utf-8"?>
<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"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<ListView
android:id="#+id/peripherals_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView android:id="#+id/peripheral_list_empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/peripheral_list_empty"/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<?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"
tools:context=".MainActivity">
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_below="#+id/txt"
android:layout_height="wrap_content"/>
</RelativeLayout>
If the system UI is on Listview will not show. Look for an icon with eye and unmark show system UI
Hi I'm new to Android Studio and currently in my activity_main xml I have this constraint layout with a few text views.
<android.support.constraint.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:id="#+id/country_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="edu.monash.fit2081.countryinfo.CountryDetails">
<TextView
android:id="#+id/textView"
android:layout_width="150dp"
android:layout_height="25dp"
//some code here
Now I want to change it to a fragment and make that activity as the bottom fragment.I made my fragment like this but how do nest the layout above into my frame layout?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_main"
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="edu.monash.fit2081.database_4.MainActivity">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_top"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/fragment_border"
/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/country_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/fragment_top"
android:background="#drawable/fragment_border"
/>
</RelativeLayout>
Any help will be appreciated!
The FrameLayout is a ViewGroup just like RelativeLayout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/country_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/fragment_top"
android:background="#drawable/fragment_border"
>
<android.support.constraint.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:id="#+id/country_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="edu.monash.fit2081.countryinfo.CountryDetails">
<TextView
android:id="#+id/textView"
android:layout_width="150dp"
android:layout_height="25dp"
/>
</FrameLayout>
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>
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.
<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"
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=".MainActivity" >
<?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="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
From this (which is from the android tutorial) I am getting an error that The processing instruction target matching "[xX][mM][lL]" is not allowed (which is on the line starting
Put <?xml version="1.0" encoding="utf-8"?> on the top of the file
Remove xmlns:android="http://schemas.android.com/apk/res/android" from LinearLayout
Put on the top below line#
<?xml version="1.0" encoding="utf-8"?>
And remove from LinearLayout below line#
xmlns:android="http://schemas.android.com/apk/res/android"
For more info refer Stackoverflow Question
I edited your layout. <?xml version="1.0" encoding="utf-8"?> this takes makes the problem:
Below layout correct:
<?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="horizontal" >
<EditText
android:id="#+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<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"
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=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
</RelativeLayout>