ViewHightActivity.java:-
package org.example.ViewHight;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ViewHightActivity extends Activity{
TextView textMyTextView, textViewWidth, textViewHeight;
Button myButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textMyTextView = (TextView)findViewById(R.id.mytextview);
textViewWidth = (TextView)findViewById(R.id.viewwidth);
textViewHeight = (TextView)findViewById(R.id.viewheight);
myButton = (Button)findViewById(R.id.mybutton);
myButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
updateSizeInfo();
}});
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
updateSizeInfo();
}
private void updateSizeInfo(){
System.out.println("===width==="+textViewHeight.getWidth());
System.out.println("===Hight==="+textViewHeight.getHeight());
//textViewWidth.setText(String.valueOf("Button's Width(pixels): " + myButton.getWidth()));
//textViewHeight.setText(String.valueOf("Button's Height(pixels): " + myButton.getHeight()));
}
}
main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/mytextview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/mybutton"
android:layout_width="200px"
android:layout_height="wrap_content"
android:text="Check my size"
/>
<TextView
android:id="@+id/viewwidth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/viewheight"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="jhasdhja ld lfjklds ljfl dsljdsl jlfjl ljlkas jdljas ljd asl d jlasjld las jljkljal jd aljdasjl jldjasl jlj"
android:textSize="20dip"
android:singleLine="false"
/>
</LinearLayout>
Comments
Post a Comment