Next/prev imagebutton?


#1

hi all,

i’m new to android and i’m working thru the examples in the book. i was doing ok until i hit the landscape view. i based my landscape view on my portrait view with the previous and next buttons. the app works fine in landscape view but i can’t get the buttons to be at the extreme lower left and right of the display. i included my -land/activity_quiz.xml. as you can see i added a “spacer” (textview) and then resorted to hardcoding its size to force the buttons into place. i realize that’s crazy. can anyone tell me how to get the buttons where i want them?

john


<TextView
    android:id="@+id/question_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:padding="24dp" />

<LinearLayout
    android:layout_width="wrap_content"
	android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|center_vertical"
	android:orientation="horizontal" >
	
	<Button 
	    android:id="@+id/true_button"
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
        android:text="@string/true_button" />
	    
	<Button 
	    android:id="@+id/false_button"
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
        android:text="@string/false_button" />

	
	     </LinearLayout>
	     
<LinearLayout
    android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_gravity="bottom"
	android:orientation="horizontal" >

	<ImageButton 
		android:id="@+id/prev_button"
		android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_gravity="left"
		android:src="@drawable/arrow_left"
		android:contentDescription="@string/prev_desc"
		/>

	<TextView
		android:layout_width="match_parent"
		android:layout_height="match_parent"
    	android:layout_gravity="center"		    
    	android:width="275dp" 
    	/>
		
    	     
	<ImageButton 
		android:id="@+id/next_button"
		android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_gravity="right"
		android:src="@drawable/arrow_right"
		android:contentDescription="@string/next_desc"
		/>

	 </LinearLayout>	      

#2

To get the Next and Previous buttons to show in the lower left and right corners, you need to have

[code]android:layout_gravity=“bottom|right”

android:layout_gravity=“bottom|left”[/code]

You have:

[code]android:layout_gravity=“right”

android:layout_gravity=“left”[/code]


#3

hi,

thanks for the response, but it didn’t fix it.

i thought layout_gravity applied to the particular layout. since all were aligned in horizontal i thought right & left would do it…but obviously that’s not the case. the left is working but i’m not sure if that’s because left is working or something else. i’m sure eventually i’ll have that ah-hah moment.

john


#4

[quote=“duetto”]hi all,

i’m new to android and i’m working thru the examples in the book. i was doing ok until i hit the landscape view. i based my landscape view on my portrait view with the previous and next buttons. the app works fine in landscape view but i can’t get the buttons to be at the extreme lower left and right of the display. i included my -land/activity_quiz.xml. as you can see i added a “spacer” (textview) and then resorted to hardcoding its size to force the buttons into place. i realize that’s crazy. can anyone tell me how to get the buttons where i want them?

john


<TextView
    android:id="@+id/question_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:padding="24dp" />

<LinearLayout
    android:layout_width="wrap_content"
	android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|center_vertical"
	android:orientation="horizontal" >
	
	<Button 
	    android:id="@+id/true_button"
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
        android:text="@string/true_button" />
	    
	<Button 
	    android:id="@+id/false_button"
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
        android:text="@string/false_button" />

	
	     </LinearLayout>
	     
<LinearLayout
    android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_gravity="bottom"
	android:orientation="horizontal" >

	<ImageButton 
		android:id="@+id/prev_button"
		android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_gravity="left"
		android:src="@drawable/arrow_left"
		android:contentDescription="@string/prev_desc"
		/>

	<TextView
		android:layout_width="match_parent"
		android:layout_height="match_parent"
    	android:layout_gravity="center"		    
    	android:width="275dp" 
    	/>
		
    	     
	<ImageButton 
		android:id="@+id/next_button"
		android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_gravity="right"
		android:src="@drawable/arrow_right"
		android:contentDescription="@string/next_desc"
		/>

	 </LinearLayout>	      

[/quote]

[color=#FF0000]Remove the linear layout that contains the two image buttons
then make the gravity for the previous image button ="bottom|left"
and for the next image button =“bottom|right”[/color]


#5

Above post solved that problem for me, here is my final land\activity_quiz.xml

<TextView 
    android:id="@+id/question_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:padding="24dp" />

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:orientation="horizontal" >
    
    <Button 
        android:id="@+id/true_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/true_button" />
    
    <Button 
        android:id="@+id/false_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/false_button" />
    
</LinearLayout>

    
    <ImageButton
        android:id="@+id/prev_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left"
        android:src="@drawable/arrow_left"
        android:contentDescription="@string/prev_button"
        />
    
    <ImageButton
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:src="@drawable/arrow_right"
        android:contentDescription="@string/next_button"
        />