Skip to content

Instantly share code, notes, and snippets.

@BetelGeuseee
Created May 9, 2020 05:31
Show Gist options
  • Save BetelGeuseee/0be101facf4b06a99e054c2451e9f85b to your computer and use it in GitHub Desktop.
Save BetelGeuseee/0be101facf4b06a99e054c2451e9f85b to your computer and use it in GitHub Desktop.
Android Linear Layout XML description in JAVA code
package com.example.rough;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
public class LinearTest extends Activity {
LinearLayout linearLayout;
Button button;
TextView textView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linearLayout = new LinearLayout(this);
button = new Button(this);
textView = new TextView(this);
LinearLayout.LayoutParams dimension = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
linearLayout.setLayoutParams(dimension);
LinearLayout.LayoutParams viewDimension = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
button.setLayoutParams(viewDimension);
textView.setLayoutParams(viewDimension);
linearLayout.setOrientation(LinearLayout.VERTICAL);
textView.setText("Shirshak");
button.setText("Next");
linearLayout.addView(textView);
linearLayout.addView(button);
setContentView(linearLayout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment