Categories
discuss

What is Android MultiDex?

There are many posts about MultiDex. I have experienced, sometimes, errors solved including multiDexEnabled true in the defaultConfig section of my build.gradle.

But, what exactly is this feature? What are the scenarios for using it?

Answer

Quoting the documentation:

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

So, the feature is: it allows your complex app to compile. The scenarios for using it are when your app fails to compile due to hitting the 64K DEX method reference limit. This appears as a build error, such as:

Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
Categories
discuss

How to import value from properties file and use it in annotation?

I have a class that is an entity:

Class.java

@Entity
public class Class {
    @Id
    @GeneratedValue
    private Long id;

    @NotNull
    @Range(min = 0, max = 10)
    private double value;
}

I want to get rid of the hard-coded values from the @Range annotation and load them from a configuration file.

constraints.properties

minVal=0
maxVal=10

This is what I’ve tried:

@Component
@Entity
@PropertySource("classpath:/constraints.properties")
public class Class {

    @Value("${minVal}")
    private final long minValue;
    @Value("${maxVal}")
    private final long maxValue;

    @Id
    @GeneratedValue
    private Long id;

    @NotNull
    @Range(min = minValue, max = maxValue)
    private double value;
}

The error I get is attribute value must be constant. How the initialization of these fields should be performed to get the result I want?

Answer

First: to inject values into a final field you have to use constructor injection see this question

This means that you pass some unknown value into the constructor.

Although the value never changes it is not constant, since the compiler cannot know this value, because its determined at runtime. And you can only use expressions as values of annotation whose value can be determined at compile time.

Thats because annotations are declared for a class not for a single instance and in your example the values of the variables are potentially diffrent for every instance.

So I would say, that what you want to achieve is not possible.

Categories
discuss

Angular Material “[$injector:unpr] Unknown provider” errors when trying to include ngMaterial $mdToast, $animate

I am trying to use ngMaterial in this app:

Bower.json file:

{
  "name": "x",
  "version": "0.0.0",
  "description": "x",
  "dependencies": {
    "bootstrap": "~3",
    "angular": "~1.4.7",
    "angular-resource": "~1.4.7",
    "angular-animate": "~1.4.7",
    "angular-mocks": "~1.4.7",
    "angular-bootstrap": "~0.13",
    "angular-ui-utils": "bower",
    "angular-ui-router": "~0.2",
    "angular-file-upload": "1.1.5",
    "angular-material": "~0.11.4"
  },
  "resolutions": {
    "angular": ">= 1.0.2"
  }
}

Config JS file:

module.exports = {
  client: {
    lib: {
      css: [
        'public/lib/bootstrap/dist/css/bootstrap.css',
        'public/lib/bootstrap/dist/css/bootstrap-theme.css',
        'public/lib/bootstrap/dist/css/angular-material.css'
      ],
      js: [
        'public/lib/angular/angular.js',
        'public/lib/angular-aria/angular-aria.js',
        'public/lib/angular-resource/angular-resource.js',
        'public/lib/angular-animate/angular-animate.js',
        'public/lib/angular-material/angular-material.js',
        'public/lib/angular-ui-router/release/angular-ui-router.js',
        'public/lib/angular-ui-utils/ui-utils.js',
        'public/lib/angular-bootstrap/ui-bootstrap-tpls.js',
        'public/lib/angular-file-upload/angular-file-upload.js'
      ],

App configuration:

// Init the application configuration module for AngularJS application
var ApplicationConfiguration = (function () {

  // Init module configuration options
  var applicationModuleName = 'x';
  var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.utils', 'angularFileUpload', 'ngMaterial'];

  // Add a new vertical module
  var registerModule = function (moduleName, dependencies) {
    // Create angular module
    angular.module(moduleName, dependencies || []);

    // Add the module to the AngularJS configuration file
    angular.module(applicationModuleName).requires.push(moduleName);
  };

  return {
    applicationModuleName: applicationModuleName,
    applicationModuleVendorDependencies: applicationModuleVendorDependencies,
    registerModule: registerModule
  };
})();

And then:

// Use Application configuration module to register a new module
ApplicationConfiguration.registerModule('core');
ApplicationConfiguration.registerModule('core.admin', ['core']);
ApplicationConfiguration.registerModule('core.admin.routes', ['ui.router']);

It fails when I try to reference ngMaterial, $mdToast or $animate in the module like below. Without the references below there are no errors on html md- references, they just don’t work properly (they will display but without ‘material’ functionality).

Controller JS file:

angular.module('core').controller('HeaderController', ['$scope', '$state', 'ngMaterial', 'Authentication', 'Menus', 
  function ($scope, $state, Authentication, Menus) {
// Add '$mdToast', '$animate',   $mdToast, $animate and the same error results 

Throws error:

Error: [$injector:unpr] Unknown provider: ngMaterialProvider <- ngMaterial <- HeaderController
http://errors.angularjs.org/1.4.7/$injector/unpr?p0=ngMaterialProvider%20%3C-%20ngMaterial%20%3C-%20HeaderController
    at http://localhost:3000/lib/angular/angular.js:68:12
    at http://localhost:3000/lib/angular/angular.js:4289:19
    at Object.getService [as get] (http://localhost:3000/lib/angular/angular.js:4437:39)
    at http://localhost:3000/lib/angular/angular.js:4294:45
    at getService (http://localhost:3000/lib/angular/angular.js:4437:39)
    at Object.invoke (http://localhost:3000/lib/angular/angular.js:4469:13)
    at extend.instance (http://localhost:3000/lib/angular/angular.js:9136:34)
    at nodeLinkFn (http://localhost:3000/lib/angular/angular.js:8248:36)
    at compositeLinkFn (http://localhost:3000/lib/angular/angular.js:7680:13)
    at publicLinkFn (http://localhost:3000/lib/angular/angular.js:7555:30) <header data-ng-include="'/modules/core/views/header.client.view.html'" class="ng-scope" data-ng-animate="1">

Answer

ngMaterial is the name of the module, it can’t be injected in the controller. You have to remove it from the following lines:

angular.module('core').controller('HeaderController', 
    ['$scope', '$state', 'ngMaterial', 'Authentication', 'Menus',  
    function ($scope, $state, Authentication, Menus) {  

Instead, ngMaterial should be added in the module dependencies of your app:

angular.module('appName', [..., 'ngMaterial', ...])

Then you can inject angular-material components, like $mdToast, in you controller.

Categories
discuss

Java 8 – External Iteration performing better than Internal Iteration?

So I was reading a book for Java 8, when I saw them doing comparison between external and internal iteration and thought about comparing the two, performance wise.

I have a method that just sums up a sequence of integers up to n.

Iterative one:

private static long iterativeSum(long n) {

    long startTime = System.nanoTime();
    long sum = 0;

    for(long i=1; i<=n; i++) {
        sum+=i;
    }


    long endTime = System.nanoTime();
    System.out.println("Iterative Sum Duration: " + (endTime-startTime)/1000000);

    return sum;
}

Sequential One – using internal iteration

private static long sequentialSum(long n) {

    long startTime = System.nanoTime();

    //long sum = LongStream.rangeClosed(1L, n)
    long sum = Stream.iterate(1L, i -> i+1)
            .limit(n)
            .reduce(0L, (i,j) -> i+j);

    long endTime = System.nanoTime();
    System.out.println("Sequential Sum Duration: " + (endTime-startTime)/1000000);

    return sum;
}

I tried to do some benchmarking on them, it turns out that the one using external iteration performs far better than the one using internal iteration.

Here’s my driver code:

public static void main(String[] args) {

    long n = 100000000L;

    for(int i=0;i<10000;i++){
    iterativeSum(n);
    sequentialSum(n);
    }
    iterativeSum(n);
    sequentialSum(n);
}

The running time for the Iteravtive one was always < 50ms whereas the execution time for Sequential one was always > 250ms.

I am not able to understand why internal iteration is not out performing external iteration here?

Answer

Even though the presented results are completely irrelevant, the observed effect actually takes place: the Stream API do has an overhead which for such simple tasks cannot be totally eliminated in real applications even after warm-up. Let’s write a JMH benchmark:

@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Fork(3)
@State(Scope.Benchmark)
public class IterativeSum {
    @Param({ "100", "10000", "1000000" })
    private int n;

    public static long iterativeSum(long n) {
        long sum = 0;

        for(long i=1; i<=n; i++) {
            sum+=i;
        }
        return sum;
    }

    @Benchmark
    public long is() {
        return iterativeSum(n);
    }
}

Here’s baseline test: plain loop. The results on my box are the following:

Benchmark             (n)  Mode  Cnt     Score     Error  Units
IterativeSum.is       100  avgt   30     0.074 ±   0.001  us/op
IterativeSum.is     10000  avgt   30     6.361 ±   0.009  us/op
IterativeSum.is   1000000  avgt   30   688.527 ±   0.910  us/op

Here’s your version of Stream API based iteration:

public static long sequentialSumBoxed(long n) {
    return Stream.iterate(1L, i -> i+1).limit(n)
                 .reduce(0L, (i,j) -> i+j);
}

@Benchmark
public long ssb() {
    return sequentialSumBoxed(n);
}

The results look like this:

Benchmark             (n)  Mode  Cnt     Score     Error  Units
IterativeSum.ssb      100  avgt   30     1.253 ±   0.084  us/op
IterativeSum.ssb    10000  avgt   30   134.959 ±   0.421  us/op
IterativeSum.ssb  1000000  avgt   30  9119.422 ±  22.817  us/op

Very disappointing: 13-21x slower. This version has many boxing operations inside, that’s why primitive stream specializations were created. Let’s check non-boxed version:

public static long sequentialSum(long n) {
    return LongStream.iterate(1L, i -> i+1).limit(n)
                     .reduce(0L, (i,j) -> i+j);
}

@Benchmark
public long ss() {
    return sequentialSum(n);
}

The results are the following:

Benchmark             (n)  Mode  Cnt     Score     Error  Units
IterativeSum.ss       100  avgt   30     0.661 ±   0.001  us/op
IterativeSum.ss     10000  avgt   30    67.498 ±   5.732  us/op
IterativeSum.ss   1000000  avgt   30  1982.687 ±  38.501  us/op

Much better now, but still 2.8-10x times slower. An alternative would be to use the range:

public static long rangeSum(long n) {
    return LongStream.rangeClosed(1, n).sum();
}

@Benchmark
public long rs() {
    return rangeSum(n);
}

The results are the following:

Benchmark             (n)  Mode  Cnt     Score     Error  Units
IterativeSum.rs       100  avgt   30     0.316 ±   0.001  us/op
IterativeSum.rs     10000  avgt   30    28.646 ±   0.065  us/op
IterativeSum.rs   1000000  avgt   30  2158.962 ± 514.780  us/op

Now it’s 3.1-4.5x times slower. The cause of this slowness is that Stream API has very long call chain which hits the MaxInlineLevel JVM limit, so it cannot be fully inlined by default. You may increase this limit setting like -XX:MaxInlineLevel=20 and get the following result:

Benchmark             (n)  Mode  Cnt     Score     Error  Units
IterativeSum.rs       100  avgt   30     0.111 ±   0.001  us/op
IterativeSum.rs     10000  avgt   30     9.552 ±   0.017  us/op
IterativeSum.rs   1000000  avgt   30   729.935 ±  31.915  us/op

Much better: now it’s only 1.05-1.5x slower.

The problem with this test is that the loop body of iterative version is very simple, thus could be efficiently unrolled and vectorized by JIT-compiler, and it’s much harder to do this with the same efficiency for sophisticated Stream API code. However in real applications you’re unlikely to sum consequtive numbers in a loop (why not write n*(n+1)/2 instead?). With real problems Stream API overhead is much lower even with default MaxInlineLevel setting.

Categories
discuss

NestedScrollview won’t start from top

I have a Recyclerview in a NestedScrollview.. everything is working fine except one thig. I have total three view in NestedScrollview First two are LinearLayout then Recyclerview. when i run my app the Activity don’t show top two layout it starts from top of the Recyclerview.

How its show my layout:

How its show my layout

How its suppose to show:

How its suppose to show

And i am loading this enite layout under a viewpager and my viewpager is a child of Coordinator Layout.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/home_layout_background">

<LinearLayout
    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="horizontal">

        <com.daimajia.slider.library.SliderLayout
            android:id="@+id/image_slider"
            android:layout_width="match_parent"
            android:layout_height="@dimen/image_slider_height"
            android:layout_marginTop="@dimen/image_slider_top_margin" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/popular_fragment_side_padding"
        android:layout_marginRight="@dimen/popular_fragment_side_padding"
        android:layout_marginTop="@dimen/popular_fragment_side_padding"
        android:orientation="horizontal"
        android:weightSum="4">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/free_delivery"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewFreeDelivery"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_free_delivery" />

                    <TextView
                        android:id="@+id/btnTextFreeDelivery"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewFreeDelivery"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/free_delivery_txt"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>

            </RelativeLayout>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/flash_deals"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">


                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewFlashDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_flash_deals" />

                    <TextView
                        android:id="@+id/btnTextFlashDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewFlashDeals"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/flash_deals_txt"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>

            </RelativeLayout>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/for_you"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewForYou"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_for_you" />

                    <TextView
                        android:id="@+id/btnTextForYou"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewForYou"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/for_you_txt"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>


            </RelativeLayout>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <RelativeLayout
                android:id="@+id/shake_deals"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_centerInParent="true"
                android:background="@color/white">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <ImageView
                        android:id="@+id/btnImageViewShakeDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/icon_shake_deals" />

                    <TextView
                        android:id="@+id/btnTextShakeDeals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/btnImageViewShakeDeals"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="2dp"
                        android:text="@string/shake_deals"
                        android:textColor="@color/popular_fragment_four_btn_txt"
                        android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                </RelativeLayout>

            </RelativeLayout>
        </RelativeLayout>
    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="@dimen/popular_fragment_side_padding"
        android:layout_marginRight="@dimen/popular_fragment_side_padding"
        android:layout_marginTop="18dp"
        android:scrollbars="none" />

</LinearLayout>

</android.support.v4.widget.NestedScrollView>

My ViewPager Layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/home_layout_background"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="center"
        android:background="@drawable/toolbar_background"
        app:layout_scrollFlags="scroll|enterAlways">

        <TextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/title_home"
            android:textColor="@color/toolbar_title_txt_color"
            android:textSize="@dimen/toolbar_txt_size"
            android:textStyle="bold" />

    </android.support.v7.widget.Toolbar>


    <android.support.design.widget.TabLayout android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        app:tabMode="scrollable"
        app:tabTextColor="@color/tab_bar_txt"
        app:tabIndicatorColor="@color/tab_bar_txt_selected"
        app:tabSelectedTextColor="@color/tab_bar_txt_selected"
        app:tabTextAppearance="@style/TabTextAppeareance"/>

</android.support.design.widget.AppBarLayout>



</android.support.design.widget.CoordinatorLayout>

Answer

It is a problem about focus. Try :

findViewById(R.id.recycler_view).setFocusable(false);
findViewById(R.id.temp).requestFocus();

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/home_layout_background">

    <LinearLayout
        android:id="@+id/temp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        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="horizontal">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/image_slider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/image_slider_height"
                android:layout_marginTop="@dimen/image_slider_top_margin" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/popular_fragment_side_padding"
            android:layout_marginRight="@dimen/popular_fragment_side_padding"
            android:layout_marginTop="@dimen/popular_fragment_side_padding"
            android:orientation="horizontal"
            android:weightSum="4">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/free_delivery"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewFreeDelivery"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_free_delivery" />

                        <TextView
                            android:id="@+id/btnTextFreeDelivery"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewFreeDelivery"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/free_delivery_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/flash_deals"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">


                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewFlashDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_flash_deals" />

                        <TextView
                            android:id="@+id/btnTextFlashDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewFlashDeals"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/flash_deals_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/for_you"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewForYou"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_for_you" />

                        <TextView
                            android:id="@+id/btnTextForYou"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewForYou"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/for_you_txt"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>


                </RelativeLayout>
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:id="@+id/shake_deals"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_centerInParent="true"
                    android:background="@color/white">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true">

                        <ImageView
                            android:id="@+id/btnImageViewShakeDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:background="@drawable/icon_shake_deals" />

                        <TextView
                            android:id="@+id/btnTextShakeDeals"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/btnImageViewShakeDeals"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="2dp"
                            android:text="@string/shake_deals"
                            android:textColor="@color/popular_fragment_four_btn_txt"
                            android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
                    </RelativeLayout>

                </RelativeLayout>
            </RelativeLayout>
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="@dimen/popular_fragment_side_padding"
            android:layout_marginRight="@dimen/popular_fragment_side_padding"
            android:layout_marginTop="18dp"
            android:scrollbars="none" />

    </LinearLayout>

    </android.support.v4.widget.NestedScrollView>
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..