On Android 4.4 KitKat, my two apps has the problem. But on the other Android platform under 4.4 like 4.0 and 2.3.3, they display well.
The device I use is LG Nexus 5.
Here are two examples:
CheckBox:
<LinearLayout
android:id="#+id/CheckBoxGroup"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="vertical" >
<CheckBox
android:id="#+id/CheckBoxRememberMe"
style="#style/FontSmallBald"
android:layout_width="150dp"
android:layout_height="50dp"
android:button="#drawable/checkbox_remember_image_state"
android:checked="true"
android:gravity="center_vertical"
android:text="#string/remember_me" >
</CheckBox>
<CheckBox
android:id="#+id/CheckBoxKeepMeLogin"
style="#style/FontSmallBald"
android:layout_width="150dp"
android:layout_height="50dp"
android:button="#drawable/checkbox_remember_image_state"
android:checked="false"
android:gravity="center_vertical"
android:text="#string/keep_me_login" />
</LinearLayout>
<style name="FontSmallBald">
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
</style>
The CheckBox is displayed like this : BOX * no space * keep me login .
But on 4.0 or 2.3.3 it is displayed like this: BOX * default DP space * keep me login .
Button:
button.setGravity(Gravity.CENTER_VERTICAL);
button.setPadding(85,0,0,0);
Althouth I set 85dp paddingLeft but it results in different appearence.
On Android 4.4 the text is much more closer(not algin at and it seems that 85dp is shrinked to 50dp) to the left edge of the button but does not on the other.
Anyone knows why on Android 4.4 the rendering is different compared with other version of Android and how to set the attribute to make them look the same?
setPadding() set padding in pixels, not dp.
You can use screen width/x for padding to get a same result.
SEE:
setPadding: http://developer.android.com/reference/android/view/View.html#setPadding(int, int, int, int)
how to get device screen size
Related
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_sales_report"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:clipToPadding="false"
android:paddingHorizontal="10dp"
android:paddingBottom="120dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/mtv_sales_report_date"
tools:listitem="#layout/item_reportings_new" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_dynamic_inner_reporting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:paddingBottom="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toBottomOf="#id/mtv_date_dynamic"
tools:listitem="#layout/item_inner_reporting" />
The inner recycler view is not scrolling I have tried many solutions, non helped me, how can I make the inner recycler view scroll vertically, they both scroll vertically.
android:layout_height="0dp" You shouldn't use this without setting either the layout weight or without constraining both the top and bottom of the view because without constraints, it might just act as wrap_content basically extending beyond the screen.
Also, for the inner view, if the orientation is vertical, then height shouldn't be wrap_content maybe changing that would help.
Also, just a tip, having both recycler be vertical is a bad idea because how would android (or the user) know which view you are scrolling on if they are together.
Issue is solved by showing only four items in the inner Recycler View, and enabling nestedScrollView = true, also handling OnTouch Events for the parent Recycler View.
My code below doesnt work for each specific scrollto or smoothScrollTo, can anyone help me?
I basically want to be able to dynamically scroll to a specific Item position in the activity, e.g. if a specific recyclerviewItem has been clicked on it will go to the activity and scroll to the specific item. The position variable has been ranging from "recyclerview.getChildAdapterPosition(itemview)" to itemview.Bottom which also doesn't work.
Help would be appreciated.
private fun focusOnView(scroll: ScrollView, itemView : View?,position :Int) {
scroll.post(Runnable {
if (editBox != null) {
val x= 1
// scroll.scrollTo(0,NestedScrollView.FOCUS_DOWN)
// scroll.smoothScrollTo(0, scroll.bottom)
scroll.smoothScrollTo(0,position)
//scroll.fullScroll(130)
}
})
}
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/contentreyclerpager"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
</RelativeLayout>
</ScrollView>
Why you use the nestedScollView smoothScrollTo with the position you have to give x,y coordonate i think in your case you can use recycleView.smoothScrollToPosition(yourPosition);
I'm trying to get a TextView/ScrollView in Kotlin to scroll to bottom after appending text.
Weird thing is, I have it working perfectly for 1 TextView, however, another (near identical) TextView doesn't work?
So after a while of struggling to find a difference, I finally found ... something ...
I was populating one of them:
textView = text
and the other
textView2.append ( text )
The one using append, would not scroll to bottom, nor would it show the shaded curve for "overScrollmode" (which is set to true).
Obviously, I was using append, because I'm adding a small amount of text, repeatedly.
The other textView, is an "all or nothing" replacement. (in reality, I don't want the latter to scroll down, I actually set it to scroll to 0,0 (top), however, I used it as a test to find this issue :) )
So why does a text view, when using append, not honor/scroll as a result ?
<androidx.cardview.widget.CardView
android:id="#+id/cvMoveHistory"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="5dp"
app:cardBackgroundColor="#025D68"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toTopOf="#id/cvMoveHint"
app:layout_constraintEnd_toStartOf="#+id/linearLayoutBoardButtons"
app:layout_constraintStart_toEndOf="#+id/frLayGameBoard"
app:layout_constraintTop_toTopOf="parent">
<ScrollView
android:id="#+id/svMoveHistory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:fillViewport="true">
<TextView
android:id="#+id/moveHistory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#939393"
android:fontFamily="monospace"
android:padding="4dp"
android:scrollbars="vertical"
android:text="123) 5e2-5e3 1a1-1a3"
android:textColor="#000000"
android:textSize="11sp" />
</ScrollView>
</androidx.cardview.widget.CardView>
and in code:
-- in onCreate
tvMoveHistory = findViewById ( R.id.moveHistory )
svMoveHistory = findViewById ( R.id.svMoveHistory )
tvMoveHistory.movementMethod = ScrollingMovementMethod()
-- to actually add text
moveHistory.append ( newText )
-- during a central Refresh routine (yes, confirmed it runs via debugger)
svMoveHistory.post {
svMoveHistory.fullScroll(View.FOCUS_DOWN)
}
What's even more strange, I created a new project, minimal with just a few objects in order to re-create the issue.
It behaves perfectly whether I use append, or just straight assign it.
So I'm again baffled as to what's causing the issue ? (ie using append in my current project means no scroll to bottom, using .text = full text means scroll to bottom works).
However, re-testing in another fresh project results in expected behaviour?
Text I'm adding is very simple, no spannable string, no bold/html markup etc.
Just simple line in format of a simple chess-like notation:
12) a5-g6 e3-h7
... etc. (+ CR ie \n at end of line for new line)
I've scoured my logic, I literally don't touch that textView for any reason other than to append a small piece of text. Occassionally (ie new game), I reset it: = ""
but aside from above code, there is nothing else updating/modifying this textview/scrollview ?
Any ideas what I'm missing?
Hi i'm new to programming so ...
I made a simple app and in MainActivity.kt I just have one textview that point to a string.
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/firsttext"
in string.xml I have
lost of text that is just her for test\n\n does not make sence\n XXX and more text\n
and in middle YYY ad some text
so far so good ,, it show text.
I also have made a settingsFragment.
In root_preferances.xml i have
<EditTextPreference
android:defaultValue="not empty"
android:key="edit_text_FrontPress"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="Front pressure should be"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:defaultValue="not empty"
android:key="edit_text_RearPress"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="Rear pressure should be"
app:useSimpleSummaryProvider="true" />
Now here is my question !
do I get the value from settings menu
edit_text_RearPress into the string.xml (on place where now XXX is show)
edit_text_FrontPress into the string.xml (on place where now YYY is show)
so that is is visible in my text
I'm new to Android programming and I'm facing a problem: I don't know how to set the position of an imageView over another imageView. I want the position to be relative, maybe with percentages, to maintain the aspect on different screens or in both landscape and portrait.
thank you!
to place an Image over another use relativelayout as the root layout for both image views. This will make both image views start at the same coordinate and you can flexibly arrange them as you like.
example :
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
>
<ImageView android:id="#+id/videoImage"
android:layout_width="match_parent"
android:layout_height="170dip"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"/>
<ImageView
android:id="#+id/playVideo"
android:src="#drawable/play_"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"/>
Alternatively you can use frame layout.