Created
July 16, 2015 14:59
-
-
Save KieronQuinn/592dd87fa28dad4bfba9 to your computer and use it in GitHub Desktop.
AppIntro with a single customizable layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.quinny898.app.offthemotorway.Fragments; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import android.widget.TextView; | |
import com.quinny898.app.offthemotorway.R; | |
import com.squareup.picasso.Picasso; | |
public class AppIntroFragment extends Fragment { | |
private static final String ARG_TITLE = "title"; | |
private static final String ARG_DESC = "desc"; | |
private static final String ARG_DRAWABLE = "drawable"; | |
private static final String ARG_COLOUR = "colour"; | |
public static AppIntroFragment newInstance(String title, String description, int imageDrawable, int colour) { | |
AppIntroFragment sampleSlide = new AppIntroFragment(); | |
Bundle args = new Bundle(); | |
args.putString(ARG_TITLE, title); | |
args.putString(ARG_DESC, description); | |
args.putInt(ARG_DRAWABLE, imageDrawable); | |
args.putInt(ARG_COLOUR, colour); | |
sampleSlide.setArguments(args); | |
return sampleSlide; | |
} | |
private int drawable, colour; | |
private String title, description; | |
public AppIntroFragment() {} | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if(getArguments() != null && getArguments().size() != 0){ | |
drawable = getArguments().getInt(ARG_DRAWABLE); | |
title = getArguments().getString(ARG_TITLE); | |
description = getArguments().getString(ARG_DESC); | |
colour = getArguments().getInt(ARG_COLOUR); | |
} | |
} | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View v = inflater.inflate(R.layout.fragment_intro, container, false); | |
TextView t = (TextView) v.findViewById(R.id.title); | |
TextView d = (TextView) v.findViewById(R.id.description); | |
ImageView i = (ImageView) v.findViewById(R.id.image); | |
LinearLayout m = (LinearLayout) v.findViewById(R.id.main); | |
t.setText(title); | |
d.setText(description); | |
i.setImageDrawable(getResources().getDrawable(drawable)); | |
m.setBackgroundColor(colour); | |
return v; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--This file is modified from the original, you may want to just take the IDs across to your layout--> | |
<?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:layout_weight="10" | |
android:id="@+id/main"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="0dp" | |
android:layout_gravity="center" | |
android:gravity="center" | |
android:paddingLeft="32dp" | |
android:layout_weight="3" | |
android:textStyle="bold" | |
android:textColor="@android:color/white" | |
android:paddingRight="32dp" | |
android:textSize="28sp" | |
android:id="@+id/title"/> | |
<LinearLayout | |
android:layout_width="fill_parent" | |
android:layout_height="0dp" | |
android:orientation="vertical" | |
android:gravity="center" | |
android:layout_weight="5"> | |
<ImageView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:paddingLeft="16dp" | |
android:id="@+id/image" | |
android:paddingRight="16dp" /> | |
</LinearLayout> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="0dp" | |
android:layout_weight="3" | |
android:layout_gravity="center" | |
android:gravity="center" | |
android:textColor="@android:color/white" | |
android:paddingLeft="64dp" | |
android:paddingRight="64dp" | |
android:textSize="16sp" | |
android:id="@+id/description" /> | |
<TextView | |
android:layout_width="fill_parent" | |
android:layout_height="64dp" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addSlide(AppIntroFragment.newInstance(title, description, image, colour)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment