I'm developing an Android app which lets the user draws and then checks if it has drawn inside a shape or not. The coordinates of the shape are retrieved by a .txt created before. Now, I created it on a Google Pixel C, so when the user draws the algorithm I made do not have any problem. I tried the app on a Galaxy Tab, which has a screen resolution of 1920 x 1200 and the shape its obviously in a different position. I made this method which converts the coordinates but it doesn't work:
public void loadShapePoints () {
BufferedReader reader = null;
Display display = getWindowManager(). getDefaultDisplay();
Point size = new Point();
display. getSize(size);
int width = size. x;
int height = size. y;
float tmp = 0;
try {
reader = new BufferedReader(new InputStreamReader(getAssets().open(protocol+cornice)));
String mLine;
for (int elem=0; (mLine = reader.readLine()) != null; elem++) {
mLine = mLine.replaceAll("\\s+","");
if (elem%2==0) {
tmp = Float.parseFloat(mLine);
} else {
float x = Float.valueOf(tmp)*(width/(float)2560);
float y = Float.valueOf(Float.parseFloat(mLine))*(height/(float)1704);
Pair p1 = new Pair(x, y);
points.add(p1);
}
}
} catch (IOException e) { } finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) { }
}
}
drawView.setShape(points);
}
I'm reading the file on this way because it is structured as well:
line 1: x1
line 2: y1
line 3: x2...
I used 2560x1740 in the conversion because it is the resolution of the Google Pixel C which I used on the emulator to develop the app.
I noticed that the only way to make it works on the Galaxy Tab A is to put 2600x2200 as coordinates (I don't know why), but obviously if I put this value it will not works as soon as I get back on the Pixel C. How can I convert them? Can the problem is that the drawing area is divided into 3 part which gets resized on different screen resolutions? This is the xml of the area:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FCFCFC"
android:orientation="vertical"
android:layout_marginTop="8dp"
tools:context=".PaintingActivity" >
<!-- Top Buttons -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/draw_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="50dp"
android:contentDescription="#string/brush"
android:background="#drawable/rounded_corners"
android:padding="13dp"
android:layout_marginTop="5dp"
android:src="#drawable/brush" />
<ImageButton
android:id="#+id/erase_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="50dp"
android:contentDescription="#string/erase"
android:background="#drawable/rounded_corners"
android:padding="13dp"
android:layout_marginTop="5dp"
android:src="#drawable/eraser" />
<ImageButton
android:id="#+id/undo_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="Undo"
android:background="#drawable/rounded_corners"
android:padding="16dp"
android:layout_marginTop="5dp"
android:src="#drawable/undo" />
</LinearLayout>
<!-- Custom View -->
<com.example.sample.DrawingView
android:id="#+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF" />
<!-- Menu in basso -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<!-- Top Row -->
<LinearLayout
android:id="#+id/toprow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/form_intro"
android:layout_marginTop="15dip"
android:layout_marginBottom="25dip" />
<EditText
android:id="#+id/edittitle"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:layout_marginBottom="25dip"
android:singleLine="true" />
</LinearLayout>
<!-- Bottom Row -->
<LinearLayout
android:id="#+id/bottomrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button_1"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="160dp"
android:layout_marginBottom="10dp"
android:background="#drawable/button_bg"
android:text="Avanti"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
This is how it looks like and its structure:
EDIT: the problem is that if I draw this segment on the Pixel C I get these coordinates:
1540.9375,
513.01074
If I do it on the Galaxy Tab A I get these:
1158.0,
279.0
I solved modifying the method as well:
public void loadShapePoints () {
BufferedReader reader = null;
float height = drawView.getCanvasHeight();
float width = drawView.getCanvasWidth();
float tmp = 0;
try {
reader = new BufferedReader(new InputStreamReader(getAssets().open(protocol+cornice)));
String mLine;
for (int elem=0; (mLine = reader.readLine()) != null; elem++) {
mLine = mLine.replaceAll("\\s+","");
if (elem%2==0) {
tmp = Float.parseFloat(mLine);
} else {
float x = (width/2540)*(Float.valueOf(tmp));
float y = (height/1109)*(Float.valueOf(Float.parseFloat(mLine)));
Pair p1 = new Pair(x, y);
points.add(p1);
}
}
} catch (IOException e) { } finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) { }
}
}
drawView.setShape(points);
}
The problem was that the drawing area was getting reduced on each device, so, since it has a different size than the screen, I had to manually calculate it and divide per the Google Pixel C drawing area size (2540x1109).
Related
Im using android studio , i have xml which have horizontalscrollview
Then linearlayout then multiple imageviews ..
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
What i need is to make this horizantalscrollview to keep automatically infinite scrolling the images till the end then repeat the scrolling again and again.
what i mean by auto scrolling that the horizontalscrollview keep scrolling without using hand
Did you try to use wrap_content in layout_width?
Now, u adapt your width layout to the width of the screen, i think that if u put the value wrap_content it will solve ur problem (u have layout_height=wrap_content, but the height is "asociated" with a Vertical scroll, not with horizontal scroll):
android:layout_width="wrap_content"
I hope this help u.
ok Thanks for your support .. i found the solution
Timer timer1 = new Timer("horizontalScrollViewTimer");
timer1.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
runOnUiThread(new Runnable() {
#Override
public void run() {
if (scrollingLeft) {
if (scroll.getScrollX() == 0) {
scroll.smoothScrollBy(5, 0);
scrollingLeft = false;
} else {
scroll.smoothScrollBy(-5, 0);
}
} else {
if (scroll.canScrollHorizontally(View.FOCUS_RIGHT)) {
scroll.smoothScrollBy(5, 0);
} else {
scroll.smoothScrollBy(-5, 0);
scrollingLeft = true;
}
}
}
});
}
}, 1000, 50);
I have tested this android keyboard, but I have detected a problem, the keyboard is not displayed at the first time when I have debug the source code I have detected that the method onDraw() in the file KeyboardView.java is not called at the first time ie when I quit the application and I go back the keyboard will be displayed after that it will be displayed for all applications.
UPDATE:
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Round up a little
if (mKeyboard == null) {
setMeasuredDimension(getPaddingLeft() + getPaddingRight(), getPaddingTop() + getPaddingBottom());
} else {
int width = mKeyboard.getMinWidth() + getPaddingLeft() + getPaddingRight();
//MeasureSpec.getSize(widthMeasureSpec) = 0 when is called at first time (and in this case onDraw will not be called),
//after that when I quit my application and reopen it the value became different of 0, onDraw will be called and keyboard is displayed
if (MeasureSpec.getSize(widthMeasureSpec) < width + 10) {
width = MeasureSpec.getSize(widthMeasureSpec);
}
setMeasuredDimension(width, mKeyboard.getHeight() + getPaddingTop() + getPaddingBottom());
}
}
I have remarked that MeasureSpec.getSize(widthMeasureSpec) is equal to 0 when it called first time.
I think this is the root cause for not displaying keyboard at first call.
Can someone have an explanation why MeasureSpec.getSize(widthMeasureSpec) returns 0?
Here is my layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/ime_background_letters" >
<FrameLayout
android:id="#+id/keyboard_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom" >
<com.android.inputmethod.latin.car.KeyboardView
android:id="#+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
app:keyTextColorPrimary="#color/ime_foreground_numbers"
android:layout_gravity="center_horizontal"
style="#style/Keyboard" />
<com.android.inputmethod.latin.car.KeyboardView
android:id="#+id/popup_keyboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/keyboard_popup_offset"
android:visibility="gone"
app:keyTextColorPrimary="#color/ime_foreground_numbers"
android:layout_gravity="top|center"
style="#style/Keyboard" />
</FrameLayout>
<FrameLayout
android:id="#+id/lockout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.935"
android:clickable="true" >
<TextView
android:id="#+id/lockout_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:layout_gravity="center"
android:textColor="#color/ime_foreground_letters"
android:textSize="#dimen/keyboard_lockout_text_size"
android:text="#string/park_to_use_keyboard" />
</FrameLayout>
</FrameLayout>
This app translates form specific graffiti shapes to text.
I have 3 categories, letters, numbers and other characters.
The starting point defines the category to choose the output from. It works will on the emulator but with changing phones (resolution) it starts to get wrong.
This is my activity for drawing the graffiti and the TextView that show the result.
This is the activity XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.soltan.app1.MainActivity"
android:background="#0e004e"
android:animateLayoutChanges="false"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/res"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffffff"
android:textDirection="anyRtl"
android:hint="#string/mess"
android:layout_above="#+id/chars" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="105dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ffffff"
android:layout_marginTop="5dp"
android:id="#+id/letters"
android
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/txt3"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textDirection="anyRtl"
android:hint="#string/txt3" />
</RelativeLayout>
<RelativeLayout
android:layout_width="175dp"
android:layout_height="90dp"
android:layout_above="#+id/letters"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ffffff"
android:layout_marginTop="5dp"
android:id="#+id/chars"
android:layout_alignParentRight="false"
android:layout_marginRight="5dp"
android:layout_alignParentEnd="false"
android:focusable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/txt1"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textDirection="anyRtl"
android:hint="#string/txt1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="175dp"
android:layout_height="90dp"
android:layout_above="#+id/letters"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#fff"
android:layout_toRightOf="#+id/chars"
android:id="#+id/numbers">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/txt2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textDirection="anyRtl"
android:hint="#string/txt2" />
</RelativeLayout>
</RelativeLayout>
This is how I choose the category for now i the java file:
private List<Point> input; // a list contains the drawn graffiti shape coordinates
private Input inserted; // instance of a class
String section; // the category from which we receive the output
boolean proceed ; // if the starting point in the allowed range
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onTouchEvent(MotionEvent touchEvent)
{
super.onTouchEvent(touchEvent);
switch(touchEvent.getAction())
{
case MotionEvent.ACTION_DOWN:
{
input = new ArrayList<>();
if(touchEvent.getY() < 1216)
{
proceed = false;
}
else if(touchEvent.getY() > 1465)
{
proceed = true;
section = "letter";
}
else if(touchEvent.getX() < 506)
{
proceed = true;
section = "char";
}
else
{
proceed = true;
section = "number";
}
//Inserting the touch event points into the array list of points
for (int h = 0; h < touchEvent.getHistorySize(); h++)
{
for (int p = 0; p < touchEvent.getPointerCount(); p++)
{
float x = touchEvent.getHistoricalX(p,h);
float y = touchEvent.getHistoricalY(p,h);
input.add(new Point(x,y));
}
}
break;
}
case MotionEvent.ACTION_MOVE:
{
//Inserting the touch event points into the array list of points
for (int h = 0; h < touchEvent.getHistorySize(); h++)
{
for (int p = 0; p < touchEvent.getPointerCount(); p++)
{
float x = touchEvent.getHistoricalX(p,h);
float y = touchEvent.getHistoricalY(p,h);
input.add(new Point(x,y));
}
}
break;
}
case MotionEvent.ACTION_UP:
{
//Inserting the touch event points into the array list of points
for (int h = 0; h < touchEvent.getHistorySize(); h++)
{
for (int p = 0; p < touchEvent.getPointerCount(); p++)
{
float x = touchEvent.getHistoricalX(p,h);
float y = touchEvent.getHistoricalY(p,h);
input.add(new Point(x,y));
}
}
if(proceed)
{
inserted = new Input();
String letter =inserted.checkPoint(input,section);
if(letter.equals(""))
{
Toast.makeText(this,"No Such Graffiti, check the our dictionary!",Toast.LENGTH_SHORT).show();
}
TextView myText =(TextView) findViewById(R.id.res);
String text = myText.getText().toString();
myText.setText(text+letter);
}
break;
}
}
return true;
}
it looks to me that you're trying to get the touchEvents from the topmost view and according to the coordinates determine which child is touched? If so this is very wrong. The way to go is to register for the children themselves the onClick or onTouch listener and just check the view's id in there to determine which one was touched.
Edit:
The easiest way to do this is to add this to all three RelativeLayouts that you gave an id:
android:onClick="myMethod"
And then add this in your activity
public void myMethod(View view) {
switch(view.getId()) {
case R.id.letters:
//do here what you wanna do with letters
break;
case R.id.chars:
//do here what you wanna do with chars
break;
case R.id.numbers:
//do here what you wanna do with numbers
break;
}
}
you can of course rename the method as you like as long as it is the same as you specified in the xml
I have a layout that I am trying to make visible and it is currently not working. The layout I want to make visible has the id "goal_reminder" below. The visibility is set to "GONE" in the xml.
Here is the xml
<?xml version="1.0" encoding="utf-8"?>
<com.View.pages.ActivityPage
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/activity_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/activitylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e7e6ee"
android:clipToPadding="false"
android:divider="#null"
android:paddingBottom="80dp" />
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="#+id/goal_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/transparent_color"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="match_parent"
android:layout_height="145dp"
android:src="#drawable/sunsetforgoal" />
<ImageView
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/goal_reminder_title"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="35dp"
android:src="#drawable/logo" />
<TextView
android:id="#+id/goal_reminder_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="No goal in progress"
android:textColor="#color/text_color"
android:textSize="26sp" />
<TextView
android:id="#+id/goal_reminder_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/goal_reminder_title"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Create a new goal in your \nprofile."
android:textColor="#color/text_color"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="#+id/playground_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:autoLink="all"
android:gravity="center_horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="#string/welcome_string"
android:textSize="18sp"
android:visibility="gone" />
</com.View.pages.ActivityPage>
Here is the onFinishInflate(I am using the Screenplay/Flow libraries so that is taking place of onCreate). As you can see I am trying to set goalReminderLayout.setVisibility(View.Visible) and it's not actually making it visible. I have tested this same line of code outside of the if statements and it works just fine. I have also tested to make sure it's reaching that line of code in the if statements and that part is working fine, the lastTriggerDate is being saved properly in Parse. I am lost on why it's working fine outside of the if statements in the onFinishInflate. I also tested with a Log.d("TestVisiblity", goalReminderLayout.getVisibility()); which returns a 0(Visible) so it seems like its visible but its not actually showing up on my screen.
Date lastTriggerDate = new Date();
Boolean noDateInParse = false;
if (currentUser.getLastTriggerDate() != null) {
lastTriggerDate = currentUser.getLastTriggerDate();
} else {
noDateInParse = true;
}
Boolean inToday = DateUtils.isToday(lastTriggerDate.getTime());
if (!inToday) {
currentUser.setLastTriggerDate(currentTime);
currentUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
goalReminderLayout.setVisibility(View.VISIBLE);
fireGoalReminderAlert();
} else {
e.printStackTrace();
}
}
});
} else if (noDateInParse) {
currentUser.setLastTriggerDate(currentTime);
currentUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
goalReminderLayout.setVisibility(View.VISIBLE);
fireGoalReminderAlert();
} else {
e.printStackTrace();
}
}
});
}
Here is the code for fireGoalReminderAlert(); It's just set to set the visibility back to gone after 10 seconds. I commented this line out when testing and still had no luck so I don't think this is causing the problem.
public void fireGoalReminderAlert() {
Runnable mRunnable;
Handler mHandler = new Handler();
mRunnable = new Runnable() {
#Override
public void run() {
goalReminderLayout.setVisibility(View.GONE);
}
};
mHandler.postDelayed(mRunnable, 10 * 1000);
}
When you set a layout to visible from gone it's always a good idea to invalidate view to allow a redraw on the layout.
goalReminderLayout.setVisibility(View.VISIBLE);
goalReminderLayout.invalidate();
look at the android documentation for more info
http://developer.android.com/reference/android/view/View.html
Try this
Handler(Looper.getMainLooper()).post {
goalReminderLayout.setVisibility(View.VISIBLE);
}
I have RTL layout and LTR layout.
at the beginning all works great, but after moving to Alerter mode
both layouts are aligned to left.
how can I fix this? or at least better inspect the situation?
is there any tool with which I can see the current layout properties and attributes in my Activity's view? The code changes many attributes from the original XMl and it's hard to follow at a specific situation.
here is my xml:
<LinearLayout
android:id="#+id/navBarBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:padding="0dp"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/navBarDistanceLayout"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone">
<MyTextView
android:id="#+id/navBarDistance"
style="#style/NavBarDistance"
android:textSize="19dp"
android:text="miles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<MyTextView
android:id="#+id/navBarDistanceUnit"
style="#style/NavBarDistUnit"
android:textSize="19dp"
android:text="0.1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/navBarDistanceLayoutRtl"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginRight="8dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|right"
android:orientation="horizontal"
android:visibility="gone">
<MyTextViewType
android:id="#+id/navBarDistanceUnitRtl"
style="#style/NavBarDistUnit"
android:textSize="19dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
/>
<MyTextViewType
android:id="#+id/navBarDistanceRtl"
style="#style/NavBarDistance"
android:textSize="19dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
and here is parts of the code:
the change to AlerterMode and then coming back to non-alrter more makes navBarDistanceLayoutRtl be aligned to left instead of right
if (bIsAlertMode)
{
...
if (rtlMode)
{
width = view.findViewById(R.id.navBarDistanceLayoutRtl).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.MATCH_PARENT);
DistanceBar.setMargins(3, 20, 3, 0);
view.findViewById(R.id.navBarDistanceLayoutRtl).setLayoutParams(DistanceBar);
}
else
{
width = view.findViewById(R.id.navBarDistanceLayout).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.MATCH_PARENT);
DistanceBar.setMargins(3, 20, 3, 0);
view.findViewById(R.id.navBarDistanceLayout).setLayoutParams(DistanceBar);
}
...
}
else
{
...
if (rtlMode)
{
width = view.findViewById(R.id.navBarDistanceLayoutRtl).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
DistanceBar.setMargins(20, 8, 3, 0);
DistanceBar.gravity = RelativeLayout.ALIGN_PARENT_RIGHT;
view.findViewById(R.id.navBarDistanceLayoutRtl).setLayoutParams(DistanceBar);
view.findViewById(R.id.navBarDistanceLayoutRtl).setVisibility(View.VISIBLE);
view.findViewById(R.id.navBarDistanceLayout).setVisibility(View.GONE);
distance = (TextView)view.findViewById(R.id.navBarDistanceRtl);
distanceUnit = (TextView)view.findViewById(R.id.navBarDistanceUnitRtl);
}
else
{
width = view.findViewById(R.id.navBarDistanceLayout).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
DistanceBar.setMargins(0, 8, 3, 0);
view.findViewById(R.id.navBarDistanceLayout).setLayoutParams(DistanceBar);
DistanceBar.gravity = RelativeLayout.ALIGN_PARENT_LEFT;
view.findViewById(R.id.navBarDistanceLayoutRtl).setVisibility(View.GONE);
view.findViewById(R.id.navBarDistanceLayout).setVisibility(View.VISIBLE);
distance = (TextView)view.findViewById(R.id.navBarDistance);
distanceUnit = (TextView)view.findViewById(R.id.navBarDistanceUnit);
}
...
}
}
android:gravity can use only for content inside of LinearLayout, TextView or other Views. if you want to RTL or LTR layout you have to use android:layout_gravity.