Add an ImageView behind an "Include" item in XML - java

I have a horizontal scroll of a couple images. I have it in its own XML file that handles just the scrolling, now I want to add an image (Which shouldnt be the size of a background) behind these scrollable items so that the image is visible between and behind the scrollable images?
How can I go about doing this?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp">
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="#layout/dotw_scrollable"/>
</LinearLayout>
I have to add the background programatically as this is a dynamic image

Change your layout to something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp">
<ImageView
android:id="#+id/my_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView>
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="#layout/dotw_scrollable"/>
</RelativeLayout>

Related

how to have drawable image filled the entire screen in a ListView in Android?

Hi guys I want to have an image that I got from the Vector Asset tab to filled the entire screen on my GridView items. Currently,it looks like this at the moment. I want to have all my TextViews and ImageView to be inside of this if possible.
Here is the necessary code
This is the XML layout that my GridView currently adapts and inflate with. Look at the top part of the code to save time to see the --> android:background="#drawable/ic_folder_white_24dp">
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ic_folder_white_24dp">
<!-- android:background="#drawable/text_view_border">-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="#+id/date_created"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="15sp"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#color/black"
android:gravity="center"/>
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:padding="8dp"
android:textColor="#color/black"
android:layout_height="250dp" />
<ImageView
android:id="#+id/psw_lock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_lock_black_24dp"
android:layout_gravity="end"
android:paddingBottom="5dp"
android:paddingRight="5dp"
android:visibility="invisible"
/>
</LinearLayout>
Here is my GridView code in my mainActivity.xml though I don't think its revelant
<GridView
android:id="#+id/grid_view"
android:layout_below="#+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:numColumns="2">
</GridView>
Lastly here is my drawable image itself. I try messing with the values though nothing points to the right direction. By default it got me 24dp.
<vector android:height="24dp" android:tint="#FFDF00"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
</vector>
Any help would be appreciative.
If you mean you want a folder on each grid item, with all the other views inside it, you'll need to set some padding on the item's layout or margins on its views, so they don't overlap the edges. Whatever works to fit the image!
If you mean you want one big folder as the entire background, you'll need to set that as the background to the GridView area in your activity's layout file. So it's the background of the whole grid container, not separate backgrounds for each item.
Also I don't think you can avoid the background being stretched to fit the view, so you'll probably need to add an ImageView with scaleType="fitCenter" or something (and you won't be able to use a LinearLayout to overlay something on that image)

Increase font size of RecyclerView items

I have a navigation bar with RecyclerView that has different items. I wish to change the font size of it.
Here is the code for navigation_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/app_background"
android:textSize="30sp"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp" />
</LinearLayout>
</ScrollView>
First and easiest way i think about is change the font size directly in your single item.
But if for some reason you dont want to do so, try to read this: Android change TextView textSize on RecyclerView adapter from Activity

Scroll up Relative Layout when scrolling up listview

I'm creating an application. and the user information is shown in a relative layout. Under the relative layout is a listview with items the user created. I want if you scroll down in the List View that the Relative Layout scroll up and eventually disappeared, and the list view is stretched over the whole screen.
Like you have in de facebook app.
Facebook Scrolling image
How do I do this, this is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6">
<ImageView
android:id="#+id/BackgroundPictureOther"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#eeeeee" />
<ImageView
android:id="#+id/profileOther"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#444444"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"/>
<TextView
android:id="#+id/profileName"
android:layout_width="wrap_content"
android:minWidth="150dp"
android:layout_centerHorizontal="true"
android:textColor="#aaa"
android:textAlignment="center"
android:textSize="30sp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"></ListView>
</LinearLayout>
</merge>
Thanks in advance!
You have 2 options here:
1) You should put your entire layout inside NestedScrollView and change ListView into RecyclerView.
2) Or you can set your layout with profile picture as header view for listview.
For this you need to put your layout with profile in other xml layout file, then inflate it in code and use listview.addHeaderView(view v)

Make EditText clickable

Good evening,
i have the following layout and i would like to make the Edit Text clickable everywhere. Also if layout_height is set to match_parent, the Edit Text clickable area works like wrap_content.
This is the layout.
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:focusable="true"
android:focusableInTouchMode="true">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<RelativeLayout
android:id="#+id/relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar">
<TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="20dp">
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</TextInputLayout>
</RelativeLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relative">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<EditText
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/note_content"
android:background="#null"
android:gravity="top"/>
</TextInputLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
How can i make the Edit Text clickable everywhere in the Relative Layout inside the Scroll View?
While I don't understand why you are wanting to do this, you could make an button with the invisible property set to true, that covers the entire layout. Then respond when user touches this invisible button.
You respond by using the EditText method called setOnEditorActionListener()
See the info on this page with the heading "Responding to action button events":
http://developer.android.com/guide/topics/ui/controls/text.html
In a scrollView you can't fill the entire view until there is content here, you are asking to make the EditText Fill the whole parent space left apart from the TextView so that you can click any part of the layout to focus on the EditText. Except you give the EditText a layout_height it will remain wrap since the layout is in the RelativeLayout' which is a child for of theScrollView`.

Overwriting paddingLeft in a LinearLayout on Android

i am currently making one android application, i moded title bar, so all content for title bar is holded in window_title.xml where i have LinearLayout set: paddingLeft="5dip" . And now i need to load one imageView on the right side of this titleBar how i am able to some kind of overwrite this paddingLeft i cant delete it as it required for text and image on the left but i need it on right too...
Here is current xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#222222">
<ImageView
android:id="#+id/header"
android:src="#drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="TextTexast"
android:textSize="10pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dip"
android:textColor="#F7F7F7"
/>
</LinearLayout>
If I understand your question correctly, you're looking to apply some padding to an ImageView that you display to the right of the titlebar TextView. You can use android:paddingRight in your root LinearLayout like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip
android:background="#222222">
Alternatively, you can specify the android:paddingRight attribute in the ImageView that you want to align to the right.
To move the grey figure to the right just set android:layout_gravity for that to "right".

Categories

Resources