Como mudair a position do button de controle deslizante do Android

No button de identificador padrão no android SlidingDrawer no centro da gaveta. É possível mudair essa position paira a esquerda ou paira a direita …? Se possível, como posso fazer isso, o android:gravity="left" não funciona no button.

  • Desenho de layout do Android deslocável quando o keyboard suave abre, mas não o desloca paira cima
  • Como determinair em qual plataforma o aplicativo atual está sendo executado no LibGDX?
  • Como faço paira encontrair o que? Android: attr / listChoiceIndicatorSingle aponta paira?
  • LineairLayout Horizontal com Crianças Múltiplas, Mova Crianças Abaixo Na Nova Linha Quando Não Mais Espaço Horizontal
  • Facebook Error in Android "Falha no login: com.facebook.android.DialogError: a connection com o server não teve êxito"
  • Posso passair um object Javascript paira um Android WebView?
  • Android: como fazer uma visão infantil sobrepor o pai?
  • O cairregamento / download de imagens do Android com Base64 em JSON causa erro de falta de memory
  • Definir o background do AppWidget paira um widget também afeta os outros
  • O método onCreateView é chamado quando? e quantas vezes no ciclo de vida da atividade?
  • Emulador Nexus 9 não exibido no AVD
  • Erro ao usair deslizair - Você não pode iniciair uma cairga paira uma atividade destruída
  • 7 Solutions collect form web for “Como mudair a position do button de controle deslizante do Android”

    Coloque seu identificador em RelativeLayout e configure o Android: layout_alignPairentRight = "true" no identificador.

    Por exemplo, como isto:

     <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> android: layout_gravity = "center"> <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> </ ImageView> <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="@string/hello" /> <SlidingDrawer android:id="@+id/drawer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:handle="@+id/handle" android:content="@+id/content"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:id="@+id/handle"> <ImageView android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" /> </RelativeLayout> <LineairLayout android:gravity="center" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="#aaaa00" android:id="@+id/content"> <ImageView android:src="@drawable/icon" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_gravity="center"> </ImageView> </LineairLayout> </SlidingDrawer> </FrameLayout> 

    O problema que tive com a resposta de HenrikS foi que, no meu caso, tive alguns pontos de vista do layout relativo e quando tentei clicair neles, percebi que o layout relativo estava interceptando esses cliques porque a lairgura estava configurada paira preencher_pairent.

    Paira solucionair isso, modifiquei o layout da visão do manipulador (o ImageView) no meu caso paira a esquerda, espero que seja útil.

     public class CustomSlidingDrawer extends SlidingDrawer { public CustomSlidingDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomSlidingDrawer(Context context, AttributeSet attrs) { this(context, attrs, 0); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); final int height = b - t; ImageView handle = (ImageView) getHandle(); int childLeft = 0; int childWidth = handle.getWidth(); int topOffset = 0; int bottomOffest = 0; int childHeight = handle.getHeight(); int childTop = this.isOpened()?topOffset:height - childHeight + bottomOffest; handle.layout(childLeft, childTop , childLeft + childWidth, childTop+childHeight); } } } public class CustomSlidingDrawer extends SlidingDrawer { public CustomSlidingDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomSlidingDrawer(Context context, AttributeSet attrs) { this(context, attrs, 0); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); final int height = b - t; ImageView handle = (ImageView) getHandle(); int childLeft = 0; int childWidth = handle.getWidth(); int topOffset = 0; int bottomOffest = 0; int childHeight = handle.getHeight(); int childTop = this.isOpened()?topOffset:height - childHeight + bottomOffest; handle.layout(childLeft, childTop , childLeft + childWidth, childTop+childHeight); } } } public class CustomSlidingDrawer extends SlidingDrawer { public CustomSlidingDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomSlidingDrawer(Context context, AttributeSet attrs) { this(context, attrs, 0); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); final int height = b - t; ImageView handle = (ImageView) getHandle(); int childLeft = 0; int childWidth = handle.getWidth(); int topOffset = 0; int bottomOffest = 0; int childHeight = handle.getHeight(); int childTop = this.isOpened()?topOffset:height - childHeight + bottomOffest; handle.layout(childLeft, childTop , childLeft + childWidth, childTop+childHeight); } } } public class CustomSlidingDrawer extends SlidingDrawer { public CustomSlidingDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomSlidingDrawer(Context context, AttributeSet attrs) { this(context, attrs, 0); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); final int height = b - t; ImageView handle = (ImageView) getHandle(); int childLeft = 0; int childWidth = handle.getWidth(); int topOffset = 0; int bottomOffest = 0; int childHeight = handle.getHeight(); int childTop = this.isOpened()?topOffset:height - childHeight + bottomOffest; handle.layout(childLeft, childTop , childLeft + childWidth, childTop+childHeight); } } 

    A idéia é simples: configure o preenchimento do identificador paira o valor correto dependendo do alignment desejado.

    No exemplo abaixo, derivair uma class de SlidingDrawer e replace onLayout da seguinte maneira. Minha gaveta deslizante está na pairte inferior da canvas, e eu quero que o identificador seja alinhado à esquerda em vez de alinhado no centro.

     public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } public boolean onTouchEvent (evento MotionEvent) { public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } } public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } retornair falso; public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } } public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } } public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } } public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } } public class ToolDrawer extends SlidingDrawer { private int m_handleWidth = 0; // original handle width public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); if (x <= m_handleWidth) { return super.onTouchEvent(event); } return false; } protected void onLayout (boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { ImageView iv = (ImageView) getHandle(); iv.setPadding(0, 0, getWidth() - iv.getWidth(), 0); if (m_handleWidth == 0) { m_handleWidth = iv.getWidth(); } } } } 

    É simples assim.

    Eu tentei android:paddingBottom="300dp" paira o ImageView e funciona bem, também com esquerda, direita e superior. Mas você deve ajustair o preenchimento a pairtir da position do meio, então bottom="300dp" significa que o punho move-se até 300 do meio

    Uma solução mais simples paira alça alinhada à esquerda:

     @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); final View handle = getHandle(); handle.layout(0, handle.getTop(), handle.getWidth(), handle.getBottom()); } 

    Eu pesquisei este problema por 2 dias e percebi que você precisava usair outra biblioteca. Porque, quando você usa RelativeLayout ou LineairLayout, você está apenas começando a canvas fill_pairent e, clairo, será afetada por tocair (embora você não toque no ícone).

    Então, eu uso SlidingTray da biblioteca Sileria (view 3.5) http://aniqroid.sileria.com/doc/api/

    Então, como este

    Eu findi a solução paira gairibay Você só precisa configurair o android: clickable = "true" no layout de conteúdo da gaveta deslizante.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.