android動態設置寬度
Ⅰ 如何動態的獲取和設置ImageView的寬度和高度
動態的獲取和設置ImageView的寬度和高度,參考實例如下:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
public class PicTest extends Activity {
private final String TAG = "Pictrue Test!!!";
private ImageView image;
private int height = 0;
private int width = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView)findViewById(R.id.ImageView01);
//height = image.getHeight();
//width = image.getWidth();
//Log.d(TAG, "height: " + height);
//Log.d(TAG, "width: " + width);
LayoutParams para;
para = image.getLayoutParams();
Log.d(TAG, "layout height0: " + para.height);
Log.d(TAG, "layout width0: " + para.width);
para.height = 300;
para.width = 300;
image.setLayoutParams(para);
Log.d(TAG, "layout height: " + para.height);
Log.d(TAG, "layout width: " + para.width);
}
}
Ⅱ android 代碼里怎麼設置控制項的寬度
你可以通過findViewById() 先獲得這個控制項剩下的就是你去調用這個控制項的方法在你的代碼裡面設置控制項的寬高了。
Ⅲ android 動態設置布局寬度
例如設置一個圖片寬高 關鍵代碼:
//取控制項當前的布局參數
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();
//設置寬度值
params.width = dip2px(MainActivity.this, width);
//設置高度值
params.height = dip2px(MainActivity.this, height);
//使設置好的布局參數應用到控制項
imageView.setLayoutParams(params);
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
高度除了可以設置成以上固定的值,也可以設置成wrap_content或match_content
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.MATCH_PARENT
1
2
1
2
在這里插入圖片描述
xml
Ⅳ android下,如何實現動畫效果那樣修改控制項的寬高
創建一個線程修改控制項大小相關數據,handler設置控制項LayoutParmas
Ⅳ android 開發的時候怎麼動態設置控制項寬高
view.setHeight(100);
Ⅵ Android中如何在代碼中設置View的寬和高
LayoutParams params = mWebViewHeader.getLayoutParams(); params.height = height; params.width = LayoutParams.FILL_PARENT; mWebViewHeader.setLayoutParams(params);
Ⅶ android 如何自動調整button寬度
權重 layout-weight,搞幾個看不見的布局布滿整個寬度
獲取屏幕寬度X,然後setwidth(X/N)
wrapcontent 然後paddingright paadingleft。。。
Ⅷ android 如何動態設置控制項的寬度和高度
android中的控制項如果在xml布局文件中把控制項的layout_width和layout_height寫成固定值了,好像就不能再在程序中更改該控制項的高度和寬度了,不知哪位大俠有何良策可以指教一二,如 xml文件內容如下: <LinearLayout android:id="@id/dialog_bottom_neutral" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="center"<Buttonandroid:id="@id/dialog_bottom_neutral_button" android:layout_width="80.0dip" android:layout_height="28.0dip" android:background="@drawable/dlg_button" android:gravity="center" android:singleLine="true" android:text="mid" android:textColor="@drawable/dlg_button_text_color" android:textSize="14.0sp" / 小弟在程序中使用button.width和button.height設置沒用,用LayoutParmas設置也沒用
Ⅸ android中gridView怎麼在代碼里動態設置每一列的寬度
1.android:layout_height="wrap_content"
2.layout.addView(progressBar, new LayoutParam(LayoutParam.FILL_PARENT, LayoutParam.FILL_PARENT));
參考看看就知道了吧