-1

I am participating in the Udacity Android Basics degree. I am struggling with the project explained below. I am yet using only basic knowledge so please do not be surprised by the code simplicity. :)) I am eager to understand how to position elements so that they appear in every phone orientation mode using RelativeLayout.

You can find the XML here.

There are two screenshots of the app displayed in portrait and auto-rotate. The portrait looks alright but in auto-rotate half of the information displayed disappears.

My second question is related to the clickable elements. Once, I made them clickable they turned into red and underlined. Is this common or I should offset this with another statement?

This is my GitHub project. Any help is appreciated.

Thanks, Iva

Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
Iva
  • 1
  • 2

2 Answers2

1

For Your First Issue of Portrait and Landscape Try to put your view contents in a scrollview so that the screen contents will be scrollable when the height of the view is more than the screen height (In Portrait and Landscape Modes)

Sample with your code

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.helloandroid.MainActivity"
android:background="#03B3E4">
  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

       Add Your Contents Here ...

  </LinearLayout>

</ScrollView>

For the Second question Textviews with android:autoLink="" always takes the color from your colorAccent in styles.xml in your project if it has text that can be linked like website or mobile or map

you can change the text color by adding android:textColorLink="yourcolorhere" to your textviews

Thanks

MGRagab
  • 224
  • 1
  • 7
  • This is great! Thanks, MGRagab. I will now test the ScrollView option for a LinerLayout. But is there a way that I can overcome the issue when using RelativeLayout? Thanks – Iva Nov 16 '17 at 13:19
  • You can put your RelativeLayout inside the LinearLayout inside the scrollview – MGRagab Nov 16 '17 at 13:20
0

For auto-rotation, you can either lock rotation for your app locking screen rotation. You can use any of the methods suggested by other developers.

But If you want to add landscape orientation to your app, then you will have to define a separate XML layout file for it. You can do so by Creating a layout-landdirectory by right clicking layout under res and putting the landscape version of your layout XML file in that directory. You can also refer to this answer for some help handle screen rotation without losing data in android

Coming to the second part of your question, if you make an element clickable, it is not supposed to turn red and underlined. I am not sure how you are making them clickable but to make an element perform a function on Click, just declare the element and define it. Then you can set an OnClick listener to it. You can see an example here making a button clickable. Youcan also try this code to make the button clickable:

 Button btn= (Button) findViewById(R.id.button_main);
    btn.setClickable(true);
Anuj B
  • 404
  • 1
  • 5
  • 14
  • Thanks, Anuj Bansal. I didn't know there is a need for a separate file for landscape orientation but that explains better. Regardless, the clickable text, it is not a button but just text like a website, phone, and address. I will see now if the 'making a button clickable' will work for the latter. – Iva Nov 16 '17 at 14:01
  • glad I could help. Yeah, we have to create seperate files for landscape mode, that way we can precisely define the app interface in landscape. Also if you want to add the click function to a textview, it can also be done the same way. Happy coding!!! – Anuj B Nov 16 '17 at 14:06
  • To avoid red text for clickable elements like the latter I've found this one and suggested by MGRagab to be working: android:textColorLink – Iva Nov 16 '17 at 14:07