Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use any approach from bellow two suggestion:</p> <p>1) If your layout design is fixed than it is better to use xml based layout (static layout) rather than adding layout run-time. </p> <p>For that first create xml layout main_Activity.xml like:</p> <p><strong>main_Activity.xml</strong></p> <pre><code>&lt;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" &gt; &lt;TextView android:id="@+id/tvDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /&gt; &lt;Imageview android:id="@+id/ivIcon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ic_launcher" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>MainActivity2 .java</strong></p> <blockquote> <p>package com.example.a_simple_ui; public class MainActivity2 extends Activity {</p> <p>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); </p> <pre><code>setContentView(textView); Intent recieve = getIntent(); String message = recieve.getStringExtra(MainActivity.EXTRA_MESSAGE); TextView textView =(TextView)findViewById(R.id.tvDesc); textView.setTextSize(40); textView.setText(message); } } </code></pre> </blockquote> <p>2) You need to add TextView and Imageview in linearlayout then need to set that linearlayout in setContentView() like:</p> <pre><code> package com.example.a_simple_ui; public class MainActivity2 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent recieve = getIntent(); String message = recieve.getStringExtra(MainActivity.EXTRA_MESSAGE); TextView textView = new TextView(this); textView.setTextSize(40); textView.setText(message); ImageView imageView = new ImageView(this); imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); imageView.setImageResource(R.drawable.ic_launcher); LinearLayout layout = new LinearLayout(this); layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(textview); layout.addView(imageView); setContentView(layout); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload