I've created a simple pinnumber keyboard using this post as a basis for my program
http://www.fampennings.nl/maarten/android/09keyboard/index.htm
My problem arises with that the soft keyboard will not fill the entire width of my screen, even though I am using the %p dimensions.
Is there away to force my keyboard view so that it automaticly fills the width of the screen? Trying to use match/fill parents has not worked.
Is there away to force my keyboard view so that it automaticly fills the width of the screen? Trying to use match/fill parents has not worked.>
Can you post your xml? Have you checked through it thoroughly to make sure that you are using match_parent in every location that relates to the width of the keyboard?
I encounter the same issue.One solution is add two flexible spacers at left and right with the same background color as the keyboard.
The layout is something as below:
<LinearLayout
android:orientation="horizontal"
android:background="#color/grey"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:background="#color/grey"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<KeyboardView
android:id="#+id/keyboard_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/grey"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyBackground="#drawable/btn_keyboard_key"
android:keyTextColor="#color/black"
android:keyTextSize="28dp"
android:labelTextSize="20dp"
android:shadowColor="#color/grey"
android:shadowRadius="0.0"
android:visibility="gone" />
<View
android:background="#color/"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
</LinearLayout>
Related
I have custom ExoPlayer control bar. It takes quite a lot of space and I want to make it a bit narrower.
Here is what I want to remove/narrower (highlighted with red):
As you see I managed to remove some spaces already by playing around with paddingTop, layout_marginTop, layout_height parameters (it used to be even larger).
But it is not enough, it still takes a lot of space.
Question: How to narrower empty areas marked on the picture?
Here is what my custom exo_player_control_view.xml looks like (removed most of the elements for the purpose of simplicity):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#CC000000"
android:layoutDirection="ltr"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="#id/exo_play"
style="#style/ExoMediaButton.Play" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="#id/exo_progress"
android:layout_width="0dp"
android:layout_height="18dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Note: I fully understand that by narrowing those areas I might make the control panel less usable. It is ok. I want at least to have an ability to change them and test how it works.
First thing you should do is define height and width of ImageButton to wrap_content so it can behave properly.
The padding above play button is due to lack of height and width
Now the main thing. if you want to remove padding of TimeBar you need to set app:touch_target_height this height increasing the padding between your play button and time bar.This height is the touch area for inner bar, you can use this to increase the user touch area without increasing bar size and this will look like padding. make size 0dp and padding will be gone
well there is one more padding that is image padding..i pulled this play button image from exoPlayer library and i found this image also have some default padding. if you want to remove that padding also then change this image.
this play button image have size in square and as you can see the play button is a triangle, so they added padding to make this image in center and square.
Extra:- you can also define the size of inner bar by using app:bar_height but remember app:bar_height cannot cross app:touch_target_height. even if you define it more then app:touch_target_height you will see no effect. you can increase these size and see more by yourself below is the final result that i got (also edited and removed image padding). the button touching the bar(button background is null time bar background is #9e0c26)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#CC000000"
android:layoutDirection="ltr"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="#id/exo_play"
style="#style/ExoMediaButton.Play"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="#id/exo_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bar_height="2dp"
app:touch_target_height="2dp" />
</LinearLayout>
</LinearLayout>
I want to create layout which consists in normal condition from image and few EditTexts as displayed in the next image
But when user starts to enter the text I need to change the layout the next way:
Soft keyboard at the bottom of screen,
EditTexts about it but Image is resized according to the size of soft keyboard as displayed here
How can I do it?
Thanks in advance
Try this code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Also set
android:windowSoftInputMode="adjustResize"
as property to your Activity in AndroidManifest.xml
I am new to android programming. I am implementing a simple calculator and I am facing issues with horizontal scroll View. I am using an edit text within Horizontal scroll view. It works completely fine for the first time but as soon as I clear the screen it retains it scrolling limit, meaning that even though there are few digits on the screen I am able to scroll more than it. What I want to achieve is to limit its scrolling. Below are the screen shots and XML code.
First Time
[Second Time][2]
It is still scroll-able even though there are few digits
<HorizontalScrollView
android:id="#+id/hsvMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:scrollbars="none"
>
<EditText
android:id="#+id/mainEditText"
android:paddingTop="10dp"
android:paddingRight="2dp"
android:background="#ffff"
android:ellipsize="end"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="55sp"
android:textStyle="bold"
/>
</HorizontalScrollView>
Try changing round the layout height/width attributes, make HorizontalScrollView layout_width="fill_parent" and EditText layout_width="wrap_content" and layout_height="wrap_content"
<HorizontalScrollView
android:id="#+id/hsvMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:scrollbars="none">
<EditText
android:id="#+id/mainEditText"
android:paddingTop="10dp"
android:paddingRight="2dp"
android:background="#ffff"
android:ellipsize="end"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="55sp"
android:textStyle="bold"/>
</HorizontalScrollView>
Edit:
The reason why is wasn't working before because you were telling the scrollview to wrap the content regardless the size of the EditText, so it would only scroll around the EditText. But if you tell the ScrollView to match_parent, it'll always be the width of the screen and then the EditText can be scroll within the parent (ScrollView) regardless of the size.
Note: use match_parent instead of fill_parent, fill_parent is now deprecated. (Although still works)
My Current Implementation
I have a HorizontalScrollView which I create in XML that houses a few LinearLayout children. I have added this code below.
There are two LinearLayout containers with the id's group_one and group_two and these are populated programmatically at run time.
I also fix the width of the HorizontalScrollView at run time depending on the amount of View objects I will be inserting.
This solution works great for when the children fit in the HorizontalScrollView without the need to scroll.
The Issue
As soon as I need to scroll (there are more children than can be displayed within the fixed width HorizontalScrollView) then the scrollbar will not go all the way to the right, even though I can see that the child layout is of the correct width, and I can see the scrollbar just will not go any further.
My Question
Why would there be a limit on the scrollbar moving any further right?
My Code
HorizontalScrollView XML
<!-- THIS IS WHERE THE PLUGIN BUTTONS ARE HOUSED -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:id="#+id/map_plugin_scroll_view"
android:background="#color/map_plugin_background">
<!-- Enclosing box to layout the two groups.-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="8dp"
android:id="#+id/group_container">
<!-- These layouts contain the map plugins. -->
<LinearLayout
android:id="#+id/group_one"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"/>
<LinearLayout
android:id="#+id/group_two"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"/>
</LinearLayout>
</HorizontalScrollView>
What Is Happening
This is an image of the correct scroll to the left. The edge of the scroll view starts on the right of the red bar. Notice the distance between the two.
This is an image of the incorrect scroll right. Compare the distances between the edges of the scroll view and where the scroll bar is stopping.
This is how I want it to look when I scroll at either end.
I have been playing with this for a while now and finally found the solution.
I was trying to add the left and right margins to the LinearLayout with the ID group_container. However for some reason the HorizontalScrollView was not respecting this and this is why I was seeing this issue.
Instead I added the left and right margins to the group_one and group_two LinearLayouts. Now the HorizontalScrollView respected these and it functions as I expected. Here is my modified code.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:id="#+id/map_plugin_scroll_view"
android:background="#color/map_plugin_background">
<!-- Enclosing box to layout the two groups.-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:id="#+id/group_container">
<!-- These layouts contain the map plugins. -->
<LinearLayout
android:id="#+id/group_one"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"/>
<LinearLayout
android:id="#+id/group_two"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"/>
</LinearLayout>
</HorizontalScrollView>
set padding right to your scrollview like this :
android:paddingRight="20dp"
I have a scrolling background that doesnt work correctly when the software keyboard is on the screen,
so I've put android:windowSoftInputMode="adjustPan" in the manifest.
This prevents the scrolling background from breaking down, but it also prevents the rest of the screen from resizing so filling out the input fields becomes anoying.
Is there a way to apply android:windowSoftInputMode="adjustPan" only on the horizontalscrollview?
<HorizontalScrollView
android:id="#+id/scrollingbackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="#+id/bg_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/background_loop"
android:adjustViewBounds="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/background_loop"
android:adjustViewBounds="true"/>
</LinearLayout>
</HorizontalScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
//the input fields
I've just put an extra linearlayout at the bottom of the scrollview and sized it programmaticly 50% of the height of the screen. So when I use android:windowSoftInputMode="adjustPan" now I can still scroll down enough to see all the elements in the scrollview.
Not the cleanest solution IMO, but it'll do for now.