Ver la Versión Completa : [ CONSULTA ] Problema con NavDrawer y Tooltip
fernandinho_90
27/11/14, 21:03:44
Hola Estimados,
Estoy ocupando el ejemplo de Navigation Drawer que aparece en la documentación de Android y he querido agregarle una librería que permite colocar Tooltip en la pantalla. La librería es la que está aquí: https://github.com/rharter/android-tooltips
Hasta aquí todo bien, pero lo que quiero hacer no me funciona. La idea es que al presionar en una de las opciones del NavDrawer, por ejemplo en Earth, sobre ella me aparezca un tooltips con alguna información (texto aun por definir). Lo que sucede es que aparece el tooltip (en color rojo en la imagen de la derecha), pero debajo del item seleccionado Y al lado del NavDrawer y no sobre éste. Adjunto imágenes del problema que tengo.
http://thumbs.subefotos.com/2eb4b1e146dc6d755196f95b6e6ff8b8o.jpg (http://subefotos.com/ver/?2eb4b1e146dc6d755196f95b6e6ff8b8o.png)http://thumbs.subefotos.com/4c8f29095ca75f3704b3528953303495o.jpg (http://subefotos.com/ver/?4c8f29095ca75f3704b3528953303495o.png)
Si alguien me pudiese ayudar, se lo agradecería.
Saludos!
JamesRevelo
28/11/14, 02:54:28
¿Estás usando el listview en el método anchor()?, por lo que veo esa es la clave para relacionar el tooltip con la lista.
Si lo estás haciendo, tal vez sea el gravity(), prueba usando otro valor.
fernandinho_90
28/11/14, 04:06:33
¿Estás usando el listview en el método anchor()?, por lo que veo esa es la clave para relacionar el tooltip con la lista.
Si lo estás haciendo, tal vez sea el gravity(), prueba usando otro valor.
Hola!
Sí, yo coloco el listview en el metodo anchor().
Modificando el gravity() del tooltip no me resulta =/ siempre queda como "atrás" del navdrawer o sino al lado como mostré en la imagen (Gravity.RIGHT).
Aquí dejo el código del tooltip que uso cuando se presiona sobre un item del navdrawer.
View contentView = createToolTipView("Tooltip below the button",
Color.WHITE, getResources().getColor(android.R.color.holo_red_l ight));
contentView.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
));
ToolTip t = new Builder(this.getApplicationContext() )
.anchor(mDrawerList)
.color(getResources().getColor(android.R.color.hol o_red_light))
.gravity(Gravity.RIGHT)
.pointerSize(POINTER_SIZE)
.contentView(contentView)
.build();
mToolTipLayout.addTooltip(t);
Método createToolTipView
public View createToolTipView(String text, int textColor, int bgColor) {
float density = getResources().getDisplayMetrics().density;
int padding = (int) (8 * density);
TextView contentView = new TextView(MainActivity.this);
contentView.setPadding(padding, padding, padding, padding);
contentView.setText(text);
contentView.setTextColor(textColor);
contentView.setBackgroundColor(bgColor);
return contentView;
}
JamesRevelo
29/11/14, 03:54:26
Mi hermano ese View aparece ubicado dentro del contenedor padre y hasta donde sé, cuando se implementa un Navigation Drawer el objeto padre es un DrawerLayout, por lo que el tooltip aparecería orientado con respecto a este y no a la lista. En este caso, el listview viene siendo un hijo de DrawerLayout, quizás si intentas añadir el tooltip al interior de la lista funcione. Algo como:
<ListView....>
<ToolTip/>
</ListView>
Nunca he intentado incrustar otro View dentro de un ListView, pero como este es un ViewGroup quizás se permita. Prueba y me dices.
fernandinho_90
29/11/14, 09:46:13
Mi hermano ese View aparece ubicado dentro del contenedor padre y hasta donde sé, cuando se implementa un Navigation Drawer el objeto padre es un DrawerLayout, por lo que el tooltip aparecería orientado con respecto a este y no a la lista. En este caso, el listview viene siendo un hijo de DrawerLayout, quizás si intentas añadir el tooltip al interior de la lista funcione. Algo como:
<ListView....>
<ToolTip/>
</ListView>Nunca he intentado incrustar otro View dentro de un ListView, pero como este es un ViewGroup quizás se permita. Prueba y me dices.
Primero que todo, graciasp por responder :gracias:
Hice lo siguiente pero lamentablemente no me funcionó :cry:
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111">
<!-- TOOLTIP -->
<com.ryanharter.android.tooltips.ToolTipLayout
android:id="@+id/tooltip_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ListView>
</android.support.v4.widget.DrawerLayout>
Cuando hice esto, y manteniendo el código ya mostrado en mi respuesta anterior.
11-29 08:44:32.973: E/AndroidRuntime(1163): FATAL EXCEPTION: main
11-29 08:44:32.973: E/AndroidRuntime(1163): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.navigationdrawer example/com.example.android.navigationdrawerexample.MainAc tivity}: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2059)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2084)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.access$600(ActivityThre ad.java:130)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1195)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.os.Handler.dispatchMessage(Handler.java:99 )
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.os.Looper.loop(Looper.java:137)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.main(ActivityThread.jav a:4745)
11-29 08:44:32.973: E/AndroidRuntime(1163): at java.lang.reflect.Method.invokeNative(Native Method)
11-29 08:44:32.973: E/AndroidRuntime(1163): at java.lang.reflect.Method.invoke(Method.java:511)
11-29 08:44:32.973: E/AndroidRuntime(1163): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:786)
11-29 08:44:32.973: E/AndroidRuntime(1163): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:553)
11-29 08:44:32.973: E/AndroidRuntime(1163): at dalvik.system.NativeStart.main(Native Method)
11-29 08:44:32.973: E/AndroidRuntime(1163): Caused by: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.widget.AdapterView.addView(AdapterView.jav a:477)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.view.LayoutInflater.rInflate(LayoutInflate r.java:750)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.view.LayoutInflater.rInflate(LayoutInflate r.java:749)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.view.LayoutInflater.inflate(LayoutInflater .java:489)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.view.LayoutInflater.inflate(LayoutInflater .java:396)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.view.LayoutInflater.inflate(LayoutInflater .java:352)
11-29 08:44:32.973: E/AndroidRuntime(1163): at com.android.internal.policy.impl.PhoneWindow.setCo ntentView(PhoneWindow.java:256)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.Activity.setContentView(Activity.java: 1867)
11-29 08:44:32.973: E/AndroidRuntime(1163): at com.example.android.navigationdrawerexample.MainAc tivity.onCreate(MainActivity.java:101)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.Activity.performCreate(Activity.java:5 008)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1079)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2023)
11-29 08:44:32.973: E/AndroidRuntime(1163): ... 11 more
JamesRevelo
30/11/14, 02:40:08
Aa ok, significa que no se puede lo que planteabamos. Allí si queda complicado el tema. Habría que leer un poco mas a fondo la API del amigo de github, tal vez hayan mas ejemplos, aclaraciones y tips para este tipo de situaciones.
fernandinho_90
30/11/14, 06:45:43
Aa ok, significa que no se puede lo que planteabamos. Allí si queda complicado el tema. Habría que leer un poco mas a fondo la API del amigo de github, tal vez hayan mas ejemplos, aclaraciones y tips para este tipo de situaciones.
No conoces otra API con la cual pudiese funcionar lo que quiero hacer ??
JamesRevelo
01/12/14, 03:01:37
Lastimosamente no amigo, nunca he trabajado con tooltips. No has pensado en escribir tu propia librería?
fernandinho_90
02/12/14, 00:12:58
Lastimosamente no amigo, nunca he trabajado con tooltips. No has pensado en escribir tu propia librería?
No, no sé como se hace eso :/
JamesRevelo
02/12/14, 03:05:50
Crea un view personalizado mi hermano. Aqui te dejo el tutorial de la documentación de android:
http://developer.android.com/training/custom-views/index.html
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.