Android scrollview remove blue light - java

When you scroll on Android using scrollview, it generates a blue light the direction you are scrolling in. How would I remove the blue light?
My manifest:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sobreScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#android:color/transparent"
android:scrollingCache="false"
android:fadingEdge="none"
android:fadingEdgeLength="0dp"
android:scrollbars="none"
android:scrollbarStyle="insideOverlay"
>
<LinearLayout
android:id="#+id/contentSobre"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
Java source code:
package com.my.app.section;
import android.content.Context;
import android.util.AttributeSet;
import com.my.app.BaseSection;
import com.my.app.R;
public class SobreSection extends BaseSection {
public SobreSection(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SobreSection(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SobreSection(Context context) {
super(context);
}
#Override
protected void onFinishInflate() {
// TODO Auto-generated method stub
super.onFinishInflate();
findViewById(R.id.sobreScrollView).setVerticalFadingEdgeEnabled(false);
findViewById(R.id.sobreScrollView).setVerticalScrollBarEnabled(false);
}
}

Try adding this to your ScrollView in your layout.xml:
android:overScrollMode="never"
or add this to your code:
findViewById(R.id.sobreScrollView).setOverScrollMode(ScrollView.OVER_SCROLL_NEV‌​ER);

Add this extra line to your ScrollView definition:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sobreScrollView"
...
android:overScrollMode="never">

Related

How to Resize the toolbar according to the length of the title?

According to the fragment in which I am setting the title of my Toolbar, but some titles are very long and the App puts three points:
What I want is to display the full title, not decrease the size of the letter, if not increase the size of the toolbar so that if the title does not reach in a line that is put in a second as if it were a wrapcontent.
How is it possible to do this?
My toolbar in XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:theme="#style/Toolbar" />
</LinearLayout>
Setting the title via Java
((NavigationDrawerActivity) activity)
.getSupportActionBar().setTitle(mytext);
I have developed a custom toolbar that tries to fit text as much as possible. You should set this custom Toolbar as action bar like this: https://developer.android.com/training/appbar/setting-up.
Here is my custom toolbar code:
MyToolbar.java:
package com.aminography.textapp;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.LayoutInflater;
public class MyToolbar extends Toolbar {
private AppCompatTextView mTitleTextView;
public MyToolbar(Context context) {
super(context);
mTitleTextView = LayoutInflater.from(context).inflate(R.layout.toolbar_title_layout, this).findViewById(R.id.titleTextView);
addView(mTitleTextView);
}
public MyToolbar(Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
mTitleTextView = LayoutInflater.from(context).inflate(R.layout.toolbar_title_layout, this).findViewById(R.id.titleTextView);
addView(mTitleTextView);
}
public MyToolbar(Context context, #Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mTitleTextView = LayoutInflater.from(context).inflate(R.layout.toolbar_title_layout, this).findViewById(R.id.titleTextView);
addView(mTitleTextView);
}
#Override
public void setTitle(int resId) {
mTitleTextView.setText(resId);
}
#Override
public void setTitle(CharSequence title) {
mTitleTextView.setText(title);
}
#Override
public void setTitleTextColor(int color) {
mTitleTextView.setTextColor(color);
}
}
toolbar_title_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/titleTextView"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:autoSizeMinTextSize="9sp"
app:autoSizeStepGranularity="0.5sp"
app:autoSizeTextType="uniform" />
</FrameLayout>

Android studio frame layout not showing up in activity_main

I'm trying to design my on tabsView, so I created framelayout,called view_tabs.xml,with all the buttons and with background and everything else and its preview looks fine, then I created class for this tabLayout called: TabsView, in which I inflated that framelayout, I connected all ImageViews to their id's and tried to add this view to activity_main.xml but when I add it I see only shape of this layout, there are no button images, no background, nothing at all.
Here's view_tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/homeTabsViewFrame"
android:layout_width="match_parent"
android:layout_height="80dp"
xmlns:tools="http://schemas.android.com/tools"
tools:layout_gravity="bottom"
tools:background="#color/light_red">
<ImageView
android:id="#+id/vst_center_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center|bottom"
android:background="#drawable/ic_launcher"
android:layout_marginBottom="10dp"/>
<ImageView
android:id="#+id/vst_start_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="24dp"
android:layout_gravity="start|bottom"
android:background="#drawable/gpsmapbutton"
android:layout_marginBottom="10dp"/>
<ImageView
android:id="#+id/vst_end_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="end|bottom"
android:layout_marginEnd="24dp"
android:background="#drawable/icon_black"
android:layout_marginBottom="10dp"/>
<View
android:id="#+id/vst_indicator"
android:layout_width="64dp"
android:layout_height="5dp"
android:layout_gravity="bottom|center"
android:layout_marginBottom="4dp"
android:background="#color/white"/>
</FrameLayout>
Here's TabsView.java
package com.hist_area.imeda.histarea.view;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.hist_area.imeda.histarea.R;
/**
* Created by imeda on 8/16/17.
*/
public class TabsView extends FrameLayout implements ViewPager.OnPageChangeListener {
private ImageView mCenterImage;
private ImageView mStartImage;
private ImageView mEndImage;
private View mIndicator;
public TabsView(Context context) {
this(context, null);
}
public TabsView(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public TabsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
LayoutInflater.from(getContext()).inflate(R.layout.view_tabs,this,true);
mCenterImage = (ImageView) findViewById(R.id.vst_center_image);
mStartImage = (ImageView) findViewById(R.id.vst_start_image);
mEndImage = (ImageView) findViewById(R.id.vst_end_image);
mIndicator = (View) findViewById(R.id.vst_indicator);
}
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
}
#Override
public void onPageScrollStateChanged(int state) {
}
}
and Here's activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:background="#color/black"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hist_area.imeda.histarea.MainActivity">
<View
android:id="#+id/home_tabs_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lignt_blue"
android:alpha="0.5"/>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.hist_area.imeda.histarea.view.TabsView
android:id="#+id/homeTabsView"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
i dont understand, but, Why not use 'include' tag?

My Toolbar compound view doesn't align with parent view group properly

I am in need of a custom toolbar for a new app that I am writing. When I try to add the view to my main layout it doesn't align properly. Can someone please explain why?
public class LjCustomToolbar extends Toolbar {
private Context context;
private LayoutInflater layoutInflater;
private TextView toolbar_title;
public LjCustomToolbar(Context context) {
super(context);
initialize(context);
}
public LjCustomToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context);
}
public LjCustomToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context);
}
private void initialize(Context context) {
this.context = context;
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.custom_toolbar, this);
}
}
custom_toolbar.xml
<Toolbar
style="#style/LjToolBarDefault"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile"
style="#style/LjBodyNormalText"
android:textColor="#color/white"
android:layout_gravity="center"
android:id="#+id/toolbar_title_text" />
</Toolbar>
activity_main.xml
<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:gravity="center_horizontal"
android:background="#color/lj_color_primary">
<us.lj.CustomViews.LjCustomToolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Click here to see my current layout
Can you show a screenshot, to see what is not working.
Why do you want to customize the Toolbar? If you want to add another views inside the toolbar you can do it in xml as all other UI elements

Custom TextView cuts off using wrap_content

I created a custom TextView, in order to add a new font:
public class CustomTextView extends TextView{
public CustomTextView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
setTypeface(SplashActivity.SECRET_CODE_TYPEFACE, Typeface.NORMAL);
}
public CustomTextView(Context context, AttributeSet attrs){
super(context, attrs);
setTypeface(SplashActivity.SECRET_CODE_TYPEFACE, Typeface.NORMAL);
}
public CustomTextView(Context context){
super(context);
setTypeface(SplashActivity.SECRET_CODE_TYPEFACE, Typeface.NORMAL);
}
}
Now, when I use this TextView, the text is cut off:
And here is my XML:
<com.whereisthemonkey.sqlsheetmanager.Graphics.CustomTextView
android:layout_width="match_parent"
android:text="#string/title"
android:textSize="56sp"
android:layout_height="wrap_content"
android:gravity="center" />
android:padding="10dp"
Add padding into your text view,as shown below:
<com.whereisthemonkey.sqlsheetmanager.Graphics.CustomTextView
android:layout_width="match_parent"
android:text="#string/title"
android:textSize="56sp"
android:padding="10dp"
android:layout_height="wrap_content"
android:gravity="center" />

Best way to achieve grid RecyclerView, where items are square images with some text below it

I'm developing a music store where we show the albums in a grid. Each item is comprised of a cover album (which is a square image) and some text below it which shows artist name, album name, etc. This is the approximate result that I want:
Cover images are not uni-sized, some are 1000x1000, some are 500x500, and maybe there'll be some other sizes.
This is the current xml layout that I use for each item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/cover"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/artistName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Here is the important part of the RecyclerView's Adapter, the rest is typical stuff:
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.artistName.setText(mAlbums.get(position).name);
Picasso.with(holder.cover.getContext())
.load(mAlbums.get(position).primaryImage)
.into(holder.cover);
}
I get this result:
The right picture is 500x500 and the other two are 1000x1000
However if I add some resize to the images
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.artistName.setText(mAlbums.get(position).name);
Picasso.with(holder.cover.getContext())
.load(mAlbums.get(position).primaryImage)
.resize(300, 300)
.centerInside()
.into(holder.cover);
}
I'll get a better result like:
300 is just a random number. I can replace it with SCREEN_WIDTH/3.
So.... Is there a better approach to tackle this problem (which I think is a very general problem in apps)?
use the following SquareRelativeLayout
package net.simplyadvanced.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
/** A RelativeLayout that will always be square -- same width and height,
* where the height is based off the width. */
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context) {
super(context);
}
public SquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#TargetApi(VERSION_CODES.LOLLIPOP)
public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Set a square layout.
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
look at the answer
Recyclerview - GridLayoutManager: Set square dimensions
you can do like this. on your activity/fragment.
private void setRecyclerView() {
productRecyclerView.setHasFixedSize(true);
final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 3);
productRecyclerView.setLayoutManager(layoutManager);
recyclerViewAdapter = new ProductListAdapter(getActivity());
productRecyclerView.setAdapter(recyclerViewAdapter);
}
or you can achieve by adding different viewholders of different row/column heights.
Use a fixed height for item xml Like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="100dp">
<ImageView
android:id="#+id/cover"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/artistName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Hope this will solve the problem

Categories