|
||
|
|
|
|||||||
| Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android |
![]() |
|
|
Herramientas |
|
#1
|
||||
|
||||
|
Problema con NavDrawer y Tooltip
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. Si alguien me pudiese ayudar, se lo agradecería. Saludos! Última edición por fernandinho_90 Día 27/11/14 a las 21:05:41. Razón: mejore resolucion imagenes |
|
|
|
#2
|
||||
|
||||
|
¿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.
__________________
Desarrollador Android
http://www.hermosaprogramacion.com/ |
|
#3
|
||||
|
||||
|
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. Código:
View contentView = createToolTipView("Tooltip below the button",
Color.WHITE, getResources().getColor(android.R.color.holo_red_light));
contentView.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
));
ToolTip t = new Builder(this.getApplicationContext() )
.anchor(mDrawerList)
.color(getResources().getColor(android.R.color.holo_red_light))
.gravity(Gravity.RIGHT)
.pointerSize(POINTER_SIZE)
.contentView(contentView)
.build();
mToolTipLayout.addTooltip(t);
Código:
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;
}
|
|
#4
|
||||
|
||||
|
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:
[PHP]<ListView....> <ToolTip/> </ListView>[/PHP] Nunca he intentado incrustar otro View dentro de un ListView, pero como este es un ViewGroup quizás se permita. Prueba y me dices.
__________________
Desarrollador Android
http://www.hermosaprogramacion.com/ |
|
#5
|
||||
|
||||
|
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:
[php]<ListView....> <ToolTip/> </ListView>[/php]Nunca he intentado incrustar otro View dentro de un ListView, pero como este es un ViewGroup quizás se permita. Prueba y me dices. ![]() ![]() Hice lo siguiente pero lamentablemente no me funcionó ![]() Código:
<!-- 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>
Código:
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.navigationdrawerexample/com.example.android.navigationdrawerexample.MainActivity}: 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(ActivityThread.java:2059)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread$H.handleMessage(ActivityThread.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.java: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$MethodAndArgsCaller.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.java:477)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.view.LayoutInflater.rInflate(LayoutInflater.java:750)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.view.LayoutInflater.rInflate(LayoutInflater.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.setContentView(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.MainActivity.onCreate(MainActivity.java:101)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.Activity.performCreate(Activity.java:5008)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-29 08:44:32.973: E/AndroidRuntime(1163): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-29 08:44:32.973: E/AndroidRuntime(1163): ... 11 more
|
|
#6
|
||||
|
||||
|
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.
__________________
Desarrollador Android
http://www.hermosaprogramacion.com/ |
|
#7
|
||||
|
||||
|
No conoces otra API con la cual pudiese funcionar lo que quiero hacer ??
|
|
#8
|
||||
|
||||
|
Lastimosamente no amigo, nunca he trabajado con tooltips. No has pensado en escribir tu propia librería?
__________________
Desarrollador Android
http://www.hermosaprogramacion.com/ |
|
#9
|
||||
|
||||
|
|
|
#10
|
||||
|
||||
|
Crea un view personalizado mi hermano. Aqui te dejo el tutorial de la documentación de android:
http://developer.android.com/trainin...ews/index.html
__________________
Desarrollador Android
http://www.hermosaprogramacion.com/ |
![]() |
Estás aquí
|
||||||
|
||||||