How do I have textview on top of my listview (code shown below)? I tried many ways of placing the textview but it just does not appear.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:gravity="center_horizontal"
android:id="#+id/nameheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:gravity="center_horizontal"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
In your code just add android:text="Maulik Dodia". I have just copy your code added TWO LINES to it. One is above one, Second is android:entries="#array/names". I have also added <string-array name="names">
<item>Maulik</item>
<item>Maulik1</item>
<item>Maulik2</item>
<item>Maulik3</item>
</string-array> to strings.xml
And It worked for me in preview of Android Studio as well as in Emulator.
Below is my code as well as Screen Shots.
activity_main.xml
<?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"
tools:context="com.XXXXXXXXXX.sotestingapp.MainActivity">
<TextView
android:id="#+id/nameheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Maulik Dodia"/>
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="#array/names"
android:gravity="center_horizontal"></ListView>
</LinearLayout>
strings.xml
<resources>
<string name="app_name">SOTestingApp</string>
<string-array name="names">
<item>Maulik</item>
<item>Maulik1</item>
<item>Maulik2</item>
<item>Maulik3</item>
</string-array>
</resources>
Hope this help.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="vertical"
>
<TextView
android:gravity="center"
android:id="#+id/nameheader"
android:text="Hello Android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Please check this if it works.
Related
I converted my website into an Android web-view using an empty activity. The only issue I'm having right now is displaying my website pages in the form of a menu in the navigation drawer. Please assist me in achieving this.
Here is my Layout Activity-main.xml code
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout 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:id="#+id/swipeRefreshLayout"
tools:context="com.developer.arsltech.MemberPortal.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="9dp"
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-2dp"
android:progress="20"
android:visibility="gone"
/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myWebView"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/relativeLayout">
<ImageView
android:layout_width="240dp"
android:layout_height="240dp"
android:src="#drawable/no_internet"
android:layout_centerHorizontal="true"
android:id="#+id/noConnectionLogo"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet Connection"
android:layout_below="#+id/noConnectionLogo"
android:textAlignment="center"
android:textSize="26sp"
android:id="#+id/txtNoConnection"/>
</RelativeLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Please assist me in achieving this.
I wanna place my floatingactionbutton on the end from the bottom of a relativelayout. How i do this as best and most practical?
Here's a screenshot, how it should look:
This functionality only works when your parent layout is a coordinator layout.This can be achieved using the app:layout_anchor="" and the app:layout_anchorGravity=""
Some thing like this:
<?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/com.example.myapp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/appBar"
>
<!-- Put your content that is supposed to be in the appbar here -->
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/your_drawable_resource_file"
app:borderWidth="0dp"
app:fabSize="normal"
app:layout_anchor="#id/appBar"
app:layout_anchorGravity="left|bottom|start"/>
</android.support.design.widget.CoordinatorLayout>
Hope this was helpful.
If your parent layout is Relative Layout.
Just use
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="#+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_plus_sign"
app:elevation="4dp"
/>
</RelativeLayout>
I am trying to have two fragments shown at the same time on a horizontal orientation of my activity alongwith a toolbar. But the toolbar overlaps the fragments. I'm not sure where to place it. Btw, the toolbar comes with a navigation view, so it's in a drawerlayout.
Here's my xml.
<android.support.v4.widget.DrawerLayout 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/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:id="#+id/main_content_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.Toolbar
android:id="#+id/main_app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<fragment
android:id="#+id/activity_fragment_main_event_list"
class="com.torneyo.torneyoadmin.fragments.EventListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/activity_fragment_main_event_detail"
class="com.torneyo.torneyoadmin.fragments.EventDetailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/main_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemIconTint="#color/colorAccent"
app:itemTextColor="#color/colorTextSecondary"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>
Thoughts? I need to have the fragments show up. I'm not sure I'm using the layouts correctly.
Thanks!
Hello I see your layout file. I think the problem in it. It should inside the relative layout. kindly see the below modified layout version. Apply it let me know if you have any question in it.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/main_app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<LinearLayout
android:id="#+id/main_content_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/main_app_toolbar"
android:orientation="horizontal">
<fragment
android:id="#+id/activity_fragment_main_event_list"
class="com.torneyo.torneyoadmin.fragments.EventListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/activity_fragment_main_event_detail"
class="com.torneyo.torneyoadmin.fragments.EventDetailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/main_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemIconTint="#color/colorAccent"
app:itemTextColor="#color/colorTextSecondary"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>
my problem is ,i am using one custom-view in my XML file ,that same XML file also contain other component such as text-view ,image-buttons,
that custom-view contains the images ,that i want on background
but it is blocking my whole layout (other components)
and i can see only custom-view
following is my code
<FrameLayout
android:id="#+id/framelayout"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<com.abc.android.image
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageview">
</com.abc.android.image>
<LinearLayout
android:id="#+id/linlayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/small1"
android:orientation="vertical">
All text view, ImageButtons
</LinearLayout>
</FrameLayout>
can anyone please tell how to use custom-view at background and other components on a foreground. means components should display over the Custom-view.
Thanx in advance.
Please check the following code. I have added just two UI widgets i.e a TextView and a Button. You can add more according to you need.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearlayout01" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<FrameLayout android:id="#+id/framelayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/imageview01"
android:background="#drawable/pic">
</ImageView>
<LinearLayout android:id="#+id/linearlayout02"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:text="Text View" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40dip"
android:textStyle="bold" android:layout_gravity="center"
android:layout_marginTop="50dip" android:textColor="#FF0000" />
<Button android:text="Button" android:layout_width="fill_parent"
android:layout_height="80dip" android:gravity="center"
android:textSize="40dip" android:textStyle="bold"
android:layout_marginTop="50dip" />
</LinearLayout>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="8dp"
android:paddingRight="8dp" android:weightSum="1">
<TextView android:id="#+id/textView1" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="0.12" android:layout_width="match_parent"
android:text="#string/songsbyyear" android:gravity="center"
android:textColor="#color/white" android:textSize="22dp"
android:background="#color/steelblue" android:textStyle="bold"></TextView>
<ListView android:layout_width="wrap_content"
android:drawSelectorOnTop="false" android:id="#android:id/list"
android:background="#color/darkslateblue" android:layout_height="456dp"> </ListView>
</LinearLayout>
I have the listview with background colors set. When I tried to move up/down, it got messy. Any suggestions to fix this issue?