1. Are you ready for the Galaxy S20? Here is everything we know so far!

Android Studio Maps: How can I move an object around a single static view

Discussion in 'Android Development' started by doug777, Jul 5, 2017.

  1. doug777

    doug777 Newbie
    Thread Starter

    I want to move a Google Map around on a view. To try to find out how to do it, I have built a simple test that attempts to move the map every 5 seconds from a timer as a demonstration (on a tablet). (I'm a beginner at Java by the way.)

    The test project compiles but crashes when run and appears to crash because of the null in the line

    View view = inflater.inflate(R.layout.activity_maps, null);

    But if the only view is from setContentView(R.layout.activity_maps); at onCreate, what should null be changed to?

    MapsActivity.java

    Code (Text):
    1.  
    2. import android.content.Context;
    3. import android.os.CountDownTimer;
    4. import android.support.v4.app.FragmentActivity;
    5. import android.os.Bundle;
    6. import android.view.LayoutInflater;
    7. import android.view.View;
    8. import android.widget.LinearLayout;
    9.  
    10. import com.google.android.gms.maps.CameraUpdateFactory;
    11. import com.google.android.gms.maps.GoogleMap;
    12. import com.google.android.gms.maps.OnMapReadyCallback;
    13. import com.google.android.gms.maps.SupportMapFragment;
    14. import com.google.android.gms.maps.model.LatLng;
    15. import com.google.android.gms.maps.model.MarkerOptions;
    16.  
    17. public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
    18.  
    19.    public GoogleMap mMap;
    20.    private int counter = 2;
    21.  
    22.    [USER=1021285]@override[/USER]
    23.    protected void onCreate(Bundle savedInstanceState) {
    24.        super.onCreate(savedInstanceState);
    25.        setContentView(R.layout.activity_maps);
    26.        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
    27.                .findFragmentById(R.id.map);
    28.        mapFragment.getMapAsync(this);
    29.        new CountDownTimer(60000, 5000) {
    30.  
    31.            public void onTick(long millisUntilFinished) {
    32.                int xpos = 0;
    33.                int ypos = 0;
    34.                int width = 0;
    35.                int height = 0;
    36.                switch(counter){
    37.                    case 1 :
    38.                        xpos = 710;
    39.                        ypos = 167;
    40.                        width = 311;
    41.                        height = 290;
    42.                        break;
    43.                    case 2 :
    44.                        xpos = 215;
    45.                        ypos = 150;
    46.                        width = 935;
    47.                        height = 495;
    48.                        break;
    49.                    case 3 :
    50.                        xpos = 215;
    51.                        ypos = 282;
    52.                        width = 300;
    53.                        height = 242;
    54.                        break;
    55.                }
    56.                if(counter == 3)
    57.                    counter = 0;
    58.                counter ++;
    59.                setLayout(xpos, ypos, width, height);
    60.            }
    61.  
    62.            public void onFinish() {}
    63.        }.start();
    64.  
    65.    }
    66.  
    67.    private void setLayout(int xpos, int ypos, int width, int height) {
    68.        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    69.        View view = inflater.inflate(R.layout.activity_maps, null);
    70.        LinearLayout layout = (LinearLayout) findViewById(view.getId());
    71.        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)layout.getLayoutParams();
    72.        params.setMargins(xpos, ypos, 0, 0);
    73.        params.width = width;
    74.        params.height = height;
    75.        layout.setLayoutParams(params);
    76.        setContentView(view);
    77.    }
    78.  
    79.  
    80.    [USER=1021285]@override[/USER]
    81.    public void onMapReady(GoogleMap googleMap) {
    82.        mMap = googleMap;
    83.  
    84.        // Add a marker in Sydney and move the camera
    85.        LatLng sydney = new LatLng(-34, 151);
    86.        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    87.        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    88.    }
    89. }
    90.  
    activity_maps.xml

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.    android:eek:rientation="horizontal" android:layout_width="match_parent"
    5.    android:layout_height="match_parent">
    6.  
    7.    <fragment xmlns:tools="http://schemas.android.com/tools"
    8.        android:id="@+id/map"
    9.        android:name="com.google.android.gms.maps.SupportMapFragment"
    10.        android:layout_width="311dp"
    11.        android:layout_height="290dp"
    12.        android:layout_marginLeft="710dp"
    13.        android:layout_marginTop="167dp"
    14.        tools:context="com.booxotel.testmap.MapsActivity" />
    15. </LinearLayout>
    16.  
    The map appears in the position and size set by activity_maps if I remove the timer and setLayout().

    The error is error 2 no such file or directory and occurs at line 4008 “in Group main” whatever that means.

    Can anyone point me in the right direction to solve the problem?

    Doug
     


    #1 doug777, Jul 5, 2017
    Last edited by a moderator: Jul 6, 2017
  2. Deleted User

    Deleted User Guest

    Please show the stack trace from your Logcat view.
     
  3. doug777

    doug777 Newbie
    Thread Starter

    Thanks for you help. Logcat view as follows

    07-06 16:22:13.970 8289-8289/? I/art: Late-enabling -Xcheck:jni
    07-06 16:22:13.988 8289-8295/? E/art: Failed sending reply to debugger: Broken pipe
    07-06 16:22:13.989 8289-8295/? I/art: Debugger is no longer active
    07-06 16:22:14.046 8289-8289/? W/ActivityThread: Application com.mysite.testmap is waiting for the debugger on port 8100...
    07-06 16:22:14.054 8289-8289/? I/System.out: Sending WAIT chunk
    07-06 16:22:15.124 8289-8295/com.mysite.testmap I/art: Debugger is active
    07-06 16:22:15.255 8289-8289/com.mysite.testmap I/System.out: Debugger has connected
    07-06 16:22:15.256 8289-8289/com.mysite.testmap I/System.out: waiting for debugger to settle...
    07-06 16:22:15.456 8289-8289/com.mysite.testmap I/System.out: waiting for debugger to settle...
    07-06 16:22:15.656 8289-8289/com.mysite.testmap I/System.out: waiting for debugger to settle...
    07-06 16:22:15.856 8289-8289/com.mysite.testmap I/System.out: waiting for debugger to settle...
    07-06 16:22:16.056 8289-8289/com.mysite.testmap I/System.out: waiting for debugger to settle...
    07-06 16:22:16.257 8289-8289/com.mysite.testmap I/System.out: waiting for debugger to settle...
    07-06 16:22:16.457 8289-8289/com.mysite.testmap I/System.out: waiting for debugger to settle...
    07-06 16:22:16.657 8289-8289/com.mysite.testmap I/System.out: debugger has settled (1447)
    07-06 16:22:16.742 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.044 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.099 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.153 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.211 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.265 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.318 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.370 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.422 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.474 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
    07-06 16:22:17.527 8289-8289/com.mysite.testmap W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/app/com.mysite.testmap-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.mysite.testmap-1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
     
  4. doug777

    doug777 Newbie
    Thread Starter

    Should add I have changed these two lines since first post and logcat is with these changes:

    ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content);
    View view = inflater.inflate(R.layout.activity_maps, rootView);
     
  5. Deleted User

    Deleted User Guest

    Sorry but that's not the stack trace. Need to see the bit which includes the application exception.
     
  6. doug777

    doug777 Newbie
    Thread Starter

    If this is not the stack trace you'll have to tell me how to find it.
     

    Attached Files:

  7. doug777

    doug777 Newbie
    Thread Starter

    Or is this it?

    "main@4007" prio=5 runnable
    java.lang.Thread.State: RUNNABLE
    at libcore.io.Posix.stat(Posix.java:-1)
    at libcore.io.BlockGuardOs.stat(BlockGuardOs.java:293)
    at java.io.File.isDirectory(File.java:522)
    at dalvik.system.DexPathList.makePathElements(DexPathList.java:232)
    at dalvik.system.DexPathList.<init>(DexPathList.java:139)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
    at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
    - locked <0xfc6> (a android.util.ArrayMap)
    at android.app.LoadedApk.getClassLoader(LoadedApk.java:376)
    - locked <0xfaf> (a android.app.LoadedApk)
    at android.app.LoadedApk.makeApplication(LoadedApk.java:569)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4729)
    at android.app.ActivityThread.-wrap1(ActivityThread.java:-1)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1424)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5466)
    at java.lang.reflect.Method.invoke(Method.java:-1)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     
  8. Deleted User

    Deleted User Guest

    When an application crashes or stops unexpectedly, it's due to a run time error. The system reports it as an 'Exception'. All uncaught run time exceptions are handled by the system framework, which sends all the output to the Logcat view.
    The stack trace is essential in tracking down problems, because it pinpoints the exact place in your code which caused the error. This is the vital piece of information you need to understand why your application is crashing. A typical stack trace is described here

    https://developer.android.com/studio/debug/stacktraces.html

    Btw I'll add this description to the README-FIRST thread in this forum. In the hope that someday, someone will actually read it. ;)
     
  9. doug777

    doug777 Newbie
    Thread Starter

    OK thanks - found it :

    --------- beginning of crash
    07-06 17:02:43.956 11641-11641/com.mysite.testmap E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mysite.testmap, PID: 11641
    android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class fragment
    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at com.mysite.testmap.MapsActivity.setLayout(MapsActivity.java:73)
    at com.mysite.testmap.MapsActivity.access$100(MapsActivity.java:19)
    at com.mysite.testmap.MapsActivity$1.onTick(MapsActivity.java:62)
    at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:133)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5466)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at com.mysite.testmap.MapsActivity.setLayout(MapsActivity.java:73)
    at com.mysite.testmap.MapsActivity.access$100(MapsActivity.java:19)
    at com.mysite.testmap.MapsActivity$1.onTick(MapsActivity.java:62)
    at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:133)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5466)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Caused by: java.lang.IllegalArgumentException: Binary XML file line #6: Duplicate id 0x7f0b0061, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3447)
    at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
    at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:378)
    at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at com.mysite.testmap.MapsActivity.setLayout(MapsActivity.java:73)
    at com.mysite.testmap.MapsActivity.access$100(MapsActivity.java:19)
    at com.mysite.testmap.MapsActivity$1.onTick(MapsActivity.java:62)
    at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:133)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5466)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    07-06 17:02:45.903 11641-11961/com.mysite.testmap W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
    07-06 17:02:45.962 11641-11961/com.mysite.testmap I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:3
    07-06 17:02:45.962 11641-11961/com.mysite.testmap I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 3
    07-06 17:02:46.029 11641-11961/com.mysite.testmap W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000004/n/arm64-v8a
     
  10. Deleted User

    Deleted User Guest

    I think the system is unhappy with your attempt to re-inflate the same content view that you just used in onCreate().
    If you wish to change the layout parameters of a view, then I don't think this is the way to go about it. Have a look at this question on SO, regarding setting of View layout parameters (Look at "Duggu's" answer)

    https://stackoverflow.com/questions...g-the-linearlayout-width-or-height-on-android
     
  11. doug777

    doug777 Newbie
    Thread Starter

    OK thanks again. I'll try that.
     
  12. Deleted User

    Deleted User Guest

    Btw the clue in the stack trace is this

    Code (Text):
    1.  
    2. at com.mysite.testmap.MapsActivity.setLayout(MapsActivity.java:73)
    3.  
    Line 73 in your code caused the problem. I'm guessing that is where you try to inflate the View?
     
  13. doug777

    doug777 Newbie
    Thread Starter

    So I've tried Duggu's solution :

    setContentView(R.id.main);
    LinearLayout layout= (LinearLayout) findViewById(R.id.left);
    int width=60;
    int height=60;
    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,height);
    layout.setLayoutParams(parms);​

    In the first line 'main' shows up as an 'unresolved symbol' - I assume this means it's undefined.
    But perhaps I don't need this line as ContentView has just been set in the onCreate handler.

    In the second line 'left' is undefined. What is this 'left' supposed to mean?
     
  14. Deleted User

    Deleted User Guest

    You weren't supposed to copy that answer verbatim. It's just a guideline and should be adapted to your application. If you really don't understand that "R.id.main" and "R.id.left" are identifiers for resources in his project (not yours), then you've got some seriously basic gaps in your knowledge of Android development. If I were you, I'd stop what you're doing, and pick up a good beginners book, to learn the basics. You cannot hope to develop apps if you don't have the foundation knowledge.
     
  15. doug777

    doug777 Newbie
    Thread Starter

    You're right, I don't know anything about android. But I don't have time to learn a whole new thing just to write this one tiny bit of an app. I only need it because there's no other way to get a google map in an app. This is all I need. So can I ask this one last question?

    Is it possible to move a map object around in the original single view initially created? Because if this can't be done then it can't work in the overall project anyway.
     
  16. Deleted User

    Deleted User Guest

    Yes, It's possible to dynamically change the screen position of any View, by changing the layout parameters.
     
  17. doug777

    doug777 Newbie
    Thread Starter

    But is this true when the object is a google map or do they prevent it as each resized re-creation of the map is perhaps regarded as a new map creation and hence ultimately chargeable. I did have to re-create the map in my javascript version. It wouldn't just let me resize and move the map around without a map re-creation.
     
  18. Deleted User

    Deleted User Guest

    I don't know about google map components, but you could try experimenting with setting the layout parameters of your map Fragment.
     
  19. doug777

    doug777 Newbie
    Thread Starter

    OK many thanks for your help.
     
  20. Deleted User

    Deleted User Guest

    Just to clarify your confusion over the example with layout parameters - the "R.id.main" refers to a View id in the XML. So in your case, your map Fragment is

    Code (Text):
    1.  
    2. android:id="@+id/map"
    3.  
    which can be referred to in your Java code with id "R.id.map"
     
  21. doug777

    doug777 Newbie
    Thread Starter

    So with setLayout now changed to this :

    private void setLayout(int xpos, int ypos, int width, int height) {
    LinearLayout layout = (LinearLayout) findViewById(R.id.map);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width,height);
    params.setMargins(xpos, ypos, 0, 0);
    layout.setLayoutParams(params);
    }
    it builds okay if you use Make Project, but if you try to run it, the build fails at
    app\build\intermediates\manifests\full\debug\AndroidManifest.xml
    with the error (The requested operation cannot be performed on a file with a user-mapped section open)
     
  22. Deleted User

    Deleted User Guest

    That doesn't make much sense. Can you post more of the log?
     
  23. doug777

    doug777 Newbie
    Thread Starter

    Yes sorry about that, something messed up my workspace.

    Here is the real error log for the new code :

    --------- beginning of crash
    07-08 16:29:19.048 6022-6022/com.mysite.testmap E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mysite.testmap, PID: 6022
    java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.widget.LinearLayout
    at com.mysite.testmap.MapsActivity.setLayout(MapsActivity.java:71)
    at com.mysite.testmap.MapsActivity.access$100(MapsActivity.java:19)
    at com.mysite.testmap.MapsActivity$1.onTick(MapsActivity.java:62)
    at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:133)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5466)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    07-08 16:29:21.010 6022-6163/com.mysite.testmap W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
    07-08 16:29:21.026 6022-6163/com.mysite.testmap I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:3
    07-08 16:29:21.026 6022-6163/com.mysite.testmap I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 3
    07-08 16:29:21.045 6022-6163/com.mysite.testmap W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000004/n/arm64-v8a
     
Loading...
Similar Threads - Android Studio Maps
  1. akmishra_99
    Replies:
    0
    Views:
    177
  2. Ronald Scholten
    Replies:
    0
    Views:
    221
  3. SeanOConnor
    Replies:
    1
    Views:
    299
  4. Alvaro Vargas
    Replies:
    0
    Views:
    329
  5. RagingRetard
    Replies:
    0
    Views:
    233
  6. Danz47
    Replies:
    0
    Views:
    878
  7. Ruben u Williams
    Replies:
    1
    Views:
    240
  8. Nightpoison
    Replies:
    0
    Views:
    463
  9. VooDooChicken
    Replies:
    1
    Views:
    166
  10. Gleis
    Replies:
    1
    Views:
    454

Share This Page

Loading...