图形:
layout_file.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="300dip"
android:orientation="vertical" android:layout_weight="0.75 ">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip" android:layout_weight="0.25">
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_margin="2dip"
android:layout_weight="0.25"
android:background="#00ffff" />
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_margin="2dip"
android:layout_weight="0.25"
android:background="#00ff00" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_margin="2dip"
android:background="#00ffff" android:layout_weight="0.25"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_margin="2dip"
android:background="#00ffff" android:layout_weight="0.25"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dib" android:layout_weight="0.25">
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_margin="2dip"
android:layout_weight="0.2"
android:background="#00ffff" />
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_margin="2dip"
android:layout_weight="0.7"
android:background="#00ff00" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="300dip"
android:orientation="vertical" android:layout_weight="0.25">
<TextView
android:layout_width="match_parent"
android:layout_height="120dip"
android:layout_margin="2dip"
android:background="#00ff00" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:background="#00ff0b" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:background="#00ff0b" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:background="#00ff0b" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:background="#00ff0b" />
</LinearLayout>
</LinearLayout>
Java代码:
package abc.sara.app.mystartu1;
import android.app.Activity;
import android.os.Bundle;
public class mystartup1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
答案 0 :(得分:0)
在您的活动中:
TextView textview;
textview = (TextView)findviewbyid(R.id.textview1);
LinearLayout.LayoutParams Params1 = new LinearLayout.LayoutParams(25,50);
textview .setLayoutParams(Params1);
//try this
答案 1 :(得分:0)
好吧,我终于找到了你的问题。尝试使用权重和TextViews更多地玩。
EditTextPreference myEdTePref = (EditTextPreference) myPref;
myEdTePref.getEditText().setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
android:layout_height="match_parent"
android:layout_weight="1"
现在看起来应该是这样的:
android:layout_weight="0.7"
答案 2 :(得分:0)
首先动态获取布局高度
LinearLayout layout = (LinearLayout)findViewById(R.id.YOUD VIEW ID);
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
this.layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
}
});
然后通过逻辑实现更改TextView高度以计算并适合屏幕:
LayoutParams params = textView.getLayoutParams();
params.height = 70;
textView.setLayoutParams(params);