<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:orientation="vertical" | |
tools:context="android.example.practiceset2.MainActivity"> | |
<TextView | |
android:id="@+id/display_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
<TextView | |
android:id="@+id/display_text_view_2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
<TextView | |
android:id="@+id/display_text_view_3" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
</LinearLayout> |
package android.example.practiceset2; | |
import android.os.Bundle; | |
import android.widget.TextView; | |
import androidx.appcompat.app.AppCompatActivity; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// PASTE CODE YOU WANT TO TEST HERE | |
int raspberryPrice = 5; | |
display1("1 box: $" + raspberryPrice); | |
raspberryPrice = 10; | |
display2("2 boxes: $" + (raspberryPrice)); | |
display3("3 boxes: $" + (raspberryPrice * 3)); | |
} | |
/** | |
* Display methods that allow the text to appear on the screen. Don't worry if you don't know | |
* how these work yet. We'll be covering them in lesson 3. | |
*/ | |
public void display(String text) { | |
TextView t = (TextView) findViewById(R.id.display_text_view); | |
t.setText(text); | |
} | |
public void display(int text) { | |
TextView t = (TextView) findViewById(R.id.display_text_view); | |
t.setText(text + ""); | |
} | |
public void display1(String text) { | |
display(text); | |
} | |
public void display2(String text) { | |
TextView t = (TextView) findViewById(R.id.display_text_view_2); | |
t.setText(text); | |
} | |
public void display3(String text) { | |
TextView t = (TextView) findViewById(R.id.display_text_view_3); | |
t.setText(text); | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
You are welcome! Go back to business:
This code above works for RelativeLayout! |
This comment has been minimized.
This comment has been minimized.
Keep only this code for your TextView and it will work fine with LinearLayout. Even you can use ScrollView I believe.
|
This comment has been minimized.
This comment has been minimized.
Heya, thanks a million. Will try it out, if I don't get it right will write again. |
This comment has been minimized.
This comment has been minimized.
That's fine :) |
This comment has been minimized.
This comment has been minimized.
A little
|
This comment has been minimized.
Hey,
Thanks for the update it really helped a lot. I have a question regarding the Linear layout and constraint layout.
If I have this code then my app works:
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
If I try to put in the Linear Layout the whole app goes blank and I can't upload the scroll View either.