有可能设置
mWebView = (WebView) findViewById(R.id.webviewHelp);
mWebView.setLayoutParams(new ViewGroup.LayoutParams(100, 200));
Run Code Online (Sandbox Code Playgroud)
这里
mWebView.setLayoutParams(new Gallery.LayoutParams(70,85));
Run Code Online (Sandbox Code Playgroud)
也测试但不工作:(
在我的活动中?我的xml文件如下
(这里我要在我的应用程序中通过XML创建webview)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/rl"
android:layout_height="360dip">
<!-- <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"-->
<!-- android:layout_height="fill_parent" />-->
<WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button android:id="@+id/My_btn"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:gravity="center" android:textSize="8px" android:text="Download this mp3 file"
android:textColor="@color/white"
android:layout_width="fill_parent" android:layout_height="33dip"
android:visibility="invisible" />
<Button android:id="@+id/My_btn1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:text="this is button !"
android:layout_width="0dip" android:layout_height="0dip"
android:visibility="invisible" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我得到这个错误和申请强行关闭
06-11 15:42:51.816: DEBUG/AndroidRuntime(323): Shutting down VM
06-11 15:42:51.816: WARN/dalvikvm(323): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
06-11 …Run Code Online (Sandbox Code Playgroud) 我试图在对话框中为一个edittext设置一些布局参数,但它似乎没有任何效果.为什么?如何减小编辑文本的宽度?
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder = new AlertDialog.Builder(context);
final EditText input = new EditText(context);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(20, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 0, 10, 0);
input.setLayoutParams(lp);
builder.setView(input)
.setCancelable(false)
.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//...
}
})
.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
Run Code Online (Sandbox Code Playgroud) 我正在向ListActivity动态添加一个按钮.如下:
setContentView(R.layout.listview_singlegrey);
LayoutInflater inflater = (LayoutInflater)this.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout linear = (LinearLayout) findViewById(R.id.list_comment);
Button btAddComment = (Button)inflater.inflate(R.layout.bt_yellow,null);
FrameLayout.LayoutParams lyp1 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
lyp1.gravity = Gravity.RIGHT;
btAddComment.setLayoutParams(lyp1);
btAddComment.setText("Añadir comentario");
Run Code Online (Sandbox Code Playgroud)
listview的LinearLayout是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent" android:id="@+id/list_comment"
android:paddingLeft="10dp" android:paddingRight="10dp" android:background="@drawable/fondomain">
<ListView android:id="@+id/android:list" android:listSelector="@android:color/transparent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:divider="@layout/linedivider" android:dividerHeight="10px"
android:cacheColorHint="#0000" android:paddingTop="10dp"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我正在膨胀的按钮布局是:
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/wrapfill"
android:background="@layout/selectoryellowbutton" android:layout_gravity="right" android:padding="10dp"
android:textSize="16px" android:text="Añadir comentario" android:textStyle="bold" android:textColor="@color/darkergray">
</Button>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我已尝试在代码和按钮中设置layout_gravity参数,但它们都不起作用.我仍然显示屏幕左侧的按钮.似乎布局参数不起作用.但是,如果我为宽度设置fill_parent,我会在整个屏幕上显示按钮,我希望按钮包裹文本并对齐屏幕右侧.
我可能遗漏了一些东西,但我找不到将子视图添加到具有特定布局参数的指定索引处的视图的方法。有addView(View v, LayoutParams lp)和有addView(View v, int index)- 但我找不到指定两者的方法。
我错过了什么?
我尝试使用以下代码动态更改微调器的宽度,但收到错误消息。正确的方法是什么?
Spinner s1 = (Spinner) findViewById(R.id.s1_10);
s1.setLayoutParams(new LayoutParams(400, LayoutParams.WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud) 我在视图寻呼机内部有一个图像视图,以显示来自网址的一些图像,如下面的屏幕截图所示,
但是,应填充图像(应占用整个视图寻呼机空间).但在我的情况下发生的是,即使我设置布局参数来填充父级,图像也会显示在中心.
我的片段,我返回布局与图像视图:
ImageView image = new ImageView(getActivity());
ImageLoader imgLoader = new ImageLoader(MainActivity.context);
imgLoader.DisplayImage(imagePath, new Activity(), image);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams());
layout.setGravity(Gravity.CENTER);
layout.addView(image);
return layout;
Run Code Online (Sandbox Code Playgroud)
查看寻呼机:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="225dp"
android:background="@color/white"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当图像仍然从url加载时,我会显示一些像动画一样的进度,一旦加载,我将在imageview中设置图像
if (bitmap != null) {
imageView.setBackgroundResource(0);
imageView.setImageBitmap(bitmap);
} else {
imageView.setBackgroundResource(R.drawable.view_pager_progress);
final AnimationDrawable startAnimation = (AnimationDrawable) imageView
.getBackground();
imageView.setScaleType(ScaleType.CENTER);// i tried FIT_XY, dint work
startAnimation.start();
}
Run Code Online (Sandbox Code Playgroud)
总结一下,我想要的是,视图内部寻呼机中的图像应该水平和垂直地填充视图寻呼机内的完整空间.知道怎么做吗?
android imageview android-layout layoutparams android-viewpager
基本上我希望searachview扩展和折叠,当后面有一个图像按钮时,当点击图标时它应该消失,当searchview崩溃时应该出现视图.
我正在使用搜索视图而不是在操作栏中.当我点击搜索图标时,它只扩展了一半的屏幕,但是它应该扩展完整的宽度,但是当我关闭搜索视图时应该是wrap_content.
<SearchView
android:id="@+id/searchView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
android.view.ViewGroup.LayoutParams params = searchview.getLayoutParams();
params.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud)
但我在这里得到错误setLayoutParams它说"添加到演员"
我有一个带有自定义适配器的ListView.
在适配器的getview中,我想将15 dip的左边距设置为某些行.基于某些条件.
-----------------------------
| Row 1 (margin 15dip) |
-----------------------------
-----------------------------
| Row 2 (margin 15dip) |
-----------------------------
-----------------------------
| Row 2.1 (margin 30dip) |
-----------------------------
-----------------------------
| Row 2.1.1 (margin 45dip) |
-----------------------------
-----------------------------
| Row 3 (margin 15dip) |
-----------------------------
Run Code Online (Sandbox Code Playgroud)
但是,当我使用以下代码设置保证金时,它给出了 ClassCastException
01-17 18:19:35.467:E/AndroidRuntime(14165):java.lang.ClassCastException:android.widget.FrameLayout $ LayoutParams无法强制转换为android.widget.AbsListView $ LayoutParams
行布局
Run Code Online (Sandbox Code Playgroud)<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/parentframeLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" > <LinearLayout android:layout_width="match_parent" android:layout_height="40dip" android:background="@color/alphaBlueMariner" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="10dip" > <ImageView android:id="@+id/offlineImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:src="@drawable/ic_object_offline" /> <ImageView android:id="@+id/parentImageView" …
这段代码工作似乎在android api 16 - 22中工作但在api 23中不起作用.我只是试图在其中显示一个带有选项的popupwindow并将背景调暗到popupwindow下面:
WindowPopUp windowPopUp =
new WindowPopUp(mContext, mPlaces.get(position), position, fromSearch);
windowPopUp.showAtLocation(v, Gravity.CENTER, 0, 0);
View parent = (View) windowPopUp.getContentView().getParent();
//dim the window in the background
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams p = (WindowManager.LayoutParams) parent.getLayoutParams();
p.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
p.dimAmount = 0.4f;
wm.updateViewLayout(parent, p);
Run Code Online (Sandbox Code Playgroud)
运行此代码会导致错误:
03-18 21:55:19.674 8814-8814/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 8814
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams
at com.bemyapp.adapter.OuterPlaceAdapter$5.onLongClick(OuterPlaceAdapter.java:400)
at android.view.View.performLongClick(View.java:5237)
at android.view.View$CheckForLongPress.run(View.java:21121)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417) …Run Code Online (Sandbox Code Playgroud) android layoutparams android-popupwindow android-6.0-marshmallow
我有一个以编程方式创建的相对布局:
RelativeLayout layout = new RelativeLayout( this );
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
Run Code Online (Sandbox Code Playgroud)
现在我有两个 TextView,我想在这个相对布局中添加它们。但问题是两个 TextViews 都显示在相对布局的左侧,彼此重叠。
textViewContainer.addView(textView1);
textViewContainer.addView(textView2);
Run Code Online (Sandbox Code Playgroud)
现在我想知道如何以编程方式设置
`android:layout_alignParentRight="true"`
Run Code Online (Sandbox Code Playgroud)
或者
`android:layout_toLeftOf="@id/textView"`
Run Code Online (Sandbox Code Playgroud)
TextViews 的属性,就像我们在 xml 中所做的那样?
android ×10
layoutparams ×10
android-view ×1
button ×1
dialog ×1
dynamic ×1
imageview ×1
java ×1
listview ×1
searchview ×1
spinner ×1
webview ×1
width ×1
xml ×1