Archivo del blog

jueves, 24 de mayo de 2018

TabLayout Horizontal Scrollable

Implementar TabLayout Horizontal Scrollable

Fuente:



Añadir dependencias
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
Crear un layout
<?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="match_parent"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:orientation="vertical">



    <android.support.design.widget.TabLayout

        android:id="@+id/tlTab"

        style="@style/AppTabLayout"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_gravity="center_horizontal"

       app:tabMode="scrollable" />

    <android.support.v4.view.ViewPager
       
android:id="@+id/vpContenido"
       
android:layout_width="match_parent"
       
android:layout_height="match_parent" />

</LinearLayout>
en values/styles añadir las caracteristicas de los tab
<resources>
   <style name="AppTabLayout" parent="Widget.Design.TabLayout">
        <item
name="tabMaxWidth">0dp</item>
        <item
name="tabIndicatorColor">?attr/colorAccent</item>
        <item
name="tabIndicatorHeight">4dp</item>
        <item
name="tabPaddingStart">6dp</item>
        <item
name="tabPaddingEnd">6dp</item>
        <item
name="tabBackground">?attr/selectableItemBackground</item>
        <item
name="tabTextAppearance">@style/AppTabTextAppearance</item>
        <item
name="tabSelectedTextColor">@color/orange</item>
    </style>

   
<!-- for text -->
   
<style name="AppTabTextAppearance" parent="TextAppearance.Design.Tab">
        <item
name="android:textSize">18sp</item>
        <item
name="android:textStyle">bold</item>
        <item
name="android:textColor">@color/orange</item>
        <item
name="textAllCaps">false</item>
    </style>

    <color
name="orange">#1015be</color>
</resources>


crear una clase
public class ViewPagerAdaptador extends FragmentPagerAdapter
{

   
private ArrayList<Fragment> arrayFragmentos;
    private
ArrayList<String> arrayTitulos;

    public
ViewPagerAdaptador(FragmentManager fm,
                             
ArrayList<Fragment> arrayFragmentos,
                             
ArrayList<String> arrayTitulos)
    {
       
super(fm);
        this
.arrayFragmentos = arrayFragmentos;
        this
.arrayTitulos = arrayTitulos;
   
}

   
@Override
   
public Fragment getItem(int position) {
       
return arrayFragmentos.get(position);
   
}

   
@Override
   
public int getCount() {
       
return arrayFragmentos.size();
   
}

   
@Nullable
    @Override
   
public CharSequence getPageTitle(int position) {
       
return arrayTitulos.get(position);
   
}
}
En el layout activity donde queramos los tabs incluir
<include layout="@layout/tab3_tab_layout"  />
en la clase activity donde queramos implementar los tabs
TabLayout mTabLayout;  // v4.support
ViewPager vpContenido;
ViewPagerAdaptador adapter;

/** import android.support.v4.app.Fragment; */
ArrayList<Fragment> arrayFragmentos;
ArrayList<String> arrayTitulos;

@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_tab3);



    mTabLayout = findViewById(R.id.tlTab);

    vpContenido = findViewById(R.id.vpContenido);



    cargarFragmentos();

    cargarTitulos();

    viewPagerEnTabLayout();

}



private void cargarFragmentos()

{

    arrayFragmentos = new ArrayList<>();

    arrayFragmentos.add(new AnteriorFragment());

    arrayFragmentos.add(new ActualFragment());

    arrayFragmentos.add(new Capilla1Fragment());

    arrayFragmentos.add(new Capilla3Fragment());

    arrayFragmentos.add(new VipFragment());

    arrayFragmentos.add(new TrasladoFragment());

}



private void cargarTitulos()

{

    arrayTitulos = new ArrayList<>();

    arrayTitulos.add("AYER");

    arrayTitulos.add("HOY");

    arrayTitulos.add("CAPILLA 1 Y 2");

    arrayTitulos.add("CAPILLA 3");

    arrayTitulos.add("VIP");

    arrayTitulos.add("TRASLADOS");

}



private void viewPagerEnTabLayout()

{

    adapter = new ViewPagerAdaptador(getSupportFragmentManager(),

            arrayFragmentos, arrayTitulos);

    vpContenido.setAdapter(adapter);

    mTabLayout.setupWithViewPager(vpContenido);

    mTabLayout.getTabAt(0).setIcon(R.mipmap.ic_ayer);

    mTabLayout.getTabAt(1).setIcon(R.mipmap.ic_hoy);

    mTabLayout.getTabAt(2).setIcon(R.mipmap.ic_cap1y2);

    mTabLayout.getTabAt(3).setIcon(R.mipmap.ic_cap3);

    mTabLayout.getTabAt(4).setIcon(R.mipmap.ic_vip);

    mTabLayout.getTabAt(5).setIcon(R.mipmap.ic_traslado); 
    TabLayout.Tab tab = mTabLayout.getTabAt(1);

    tab.select();

}



jueves, 17 de mayo de 2018

Botones redondeados en Android


Para lo que deseas lograr, no se usa un StateListDrawable (selector) se usa un ShapeDrawable (shape) :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <solid android:color="#ffffff"/>    

    <stroke android:width="3dp"
            android:color="#ff000000"/>

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"/> 

    <corners android:radius="30px"/> 
</shape>
selector, es usado cuando deseas crear un StateListDrawable. Para crear un drawable para generar bordes redondeados en tu botton debes usar un ShapeDrawable.
Puedes revisar la documentación de los tipos de drawable usados en android y su estructura:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Como ejemplo el .xml anterior lo guardamos dentro del folder /drawable con el nombre borde_redondo.xml y en nuestro botón lo cargamos como background:
<Button
    android:id="@+id/btnRedondo"
    android:layout_width="159dp"
    android:layout_height="wrap_content"
    android:text="bordes redondos"
    android:textColor="#000000"
    android:background="@drawable/borde_redondo"/>
Tendremos como resultado:
introducir la descripción de la imagen aquí 
Android Studio Tutorial Shape Drawable Demo


Top 5 plugins para Android Studio


Fuente : https://www.youtube.com/watch?v=qd0QaYq52xg



Plugins Android Studio Exynap: https://www.youtube.com/redirect?redir_token=5-Zk2P596nNDqCHT9VtMN2i0fjJ8MTUyNjY2MDE1NkAxNTI2NTczNzU2&q=https%3A%2F%2Fplugins.jetbrains.com%2Fplugin%2F8600-exynap&v=qd0QaYq52xg&event=video_description

DTO generator: https://www.youtube.com/redirect?redir_token=5-Zk2P596nNDqCHT9VtMN2i0fjJ8MTUyNjY2MDE1NkAxNTI2NTczNzU2&q=https%3A%2F%2Fplugins.jetbrains.com%2Fplugin%2F7834-dto-generator&v=qd0QaYq52xg&event=video_description

Prettify: https://www.youtube.com/redirect?redir_token=5-Zk2P596nNDqCHT9VtMN2i0fjJ8MTUyNjY2MDE1NkAxNTI2NTczNzU2&q=https%3A%2F%2Fplugins.jetbrains.com%2Fplugin%2F7405-android-studio-prettify&v=qd0QaYq52xg&event=video_description

Drawable Importer: https://www.youtube.com/redirect?redir_token=5-Zk2P596nNDqCHT9VtMN2i0fjJ8MTUyNjY2MDE1NkAxNTI2NTczNzU2&q=https%3A%2F%2Fplugins.jetbrains.com%2Fplugin%2F7658-android-drawable-importer&v=qd0QaYq52xg&event=video_description

Android WiFi ADB: https://www.youtube.com/redirect?redir_token=5-Zk2P596nNDqCHT9VtMN2i0fjJ8MTUyNjY2MDE1NkAxNTI2NTczNzU2&q=https%3A%2F%2Fplugins.jetbrains.com%2Fplugin%2F7983-android-wifi-adb&v=qd0QaYq52xg&event=video_description


Musica Dj Quads: https://www.youtube.com/redirect?redir_token=5-Zk2P596nNDqCHT9VtMN2i0fjJ8MTUyNjY2MDE1NkAxNTI2NTczNzU2&q=https%3A%2F%2Fsoundcloud.com%2Faka-dj-quads%2Fthe-improv&v=qd0QaYq52xg&event=video_description


 

miércoles, 16 de mayo de 2018

Reproducir Video en Android Studio usando VideoView

Fuente

en androidManifest.xml

<uses-permission  
android:name="android.permission.INTERNET"/>

en layout

<VideoView     
android:id="@+id/videoView" 
 android:layout_width="match_parent"     
android:layout_height="wrap_content" />
 

crear una clase

public class ReproducirVideo
{
    
    public ReproducirVideo(Context context, Uri uri,  
         VideoView videoView)
    {

        VideoView video = videoView;         
        video.setMediaController(
               new MediaController(context));         
        video.setVideoURI(uri);
        video.requestFocus();
        video.start();
     }
}

en la activity

VideoView videoView = findViewById(R.id.videoView);
Uri uri = Uri.parse( 
"http://techslides.com/demos/sample-videos/small.mp4");
ReproducirVideo r = new ReproducirVideo( 
this, uri, videoView);

viernes, 10 de noviembre de 2017

Android Studio Mostrar imagen web

Mostrar imagenes web

1,-En el archivo AndoridManifest.xml :
  • añadir permisos :
    <uses-permission android:name="android.permission.INTERNET" />


2,- En el archivo build.gradle, en la sección dependencias incluir
  • implementation 'com.squareup.picasso:picasso:2.5.2'
3,- crear un layout para ver la imagen

4,- En el archivo MainActivity añadir, donde datos[position].getFoto() es una url
  • Picasso.with(MainActivity.this)
            .load(datos[position].getFoto())
            .error(R.mipmap.ic_launcher)
            .fit()
            .centerInside()
            .into(imagen);