import android.graphics.Color;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import static android.view.ViewGroup.*;
import static android.widget.LinearLayout.*;
import static com.example.e560.m1001a.R.id.wrap_content;
public class MainActivity extends AppCompatActivity {
public static boolean j = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
t1();
}
protected void t1(){
final LinearLayout ll = new LinearLayout(this);
final TextView tv1 = new TextView(this);
final TextView tv2 = new TextView(this);
final Button tb = new Button(this);
tv1.setBackgroundColor(Color.BLUE);
tv1.setText("" + Color.BLUE);
tv2.setBackgroundColor(Color.CYAN);
tv2.setText("" + Color.CYAN);
tb.setText("button");
ll.addView(tv1);
ll.addView(tv2);
ll.addView(tb);
setContentView(ll);
tb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Button b = (Button)v;
if(j){
j = false;
ll.setOrientation(VERTICAL);
tv2.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
tv1.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
tb.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
}else{
j = true;
ll.setOrientation(HORIZONTAL);
tv2.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
tv1.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
tb.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
}
setContentView(ll);
}
});
}
}
0 件のコメント:
コメントを投稿