我有一个线性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_menu"
android:layout_width="fill_parent"
android:layout_height="70px"
android:layout_alignParentBottom="true"
android:background="@drawable/footer_bar"
android:gravity="center" >
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当我设定条件
if (constant.getscreenresolution() >= 800) {
//i want to make it height * 2
}
Run Code Online (Sandbox Code Playgroud)
那么如何设定layout params?
我想垂直自动生成按钮,按钮之间的底边距为20px.我尝试使用LayoutParams对象设置边距,但没有成功.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/regions_search"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="30dip"
android:orientation="vertical" >
</LinearLayout>
@Override
public void onCreate(Bundle savedInstanceState) {
...
for (Region region : regionsList) {
//create new button
Button button = new Button(mContext);
//set infos
int id = Integer.parseInt(Long.toString((Long) region.getId())); button.setId(id);
button.setText(region.getName() + "( " + region.getStores_nb() + " )");
//Layoutparams setting
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 20);
button.setLayoutParams(params);
myLinear.addView(button);
}
Run Code Online (Sandbox Code Playgroud)
正如您在图像上看到的那样,图像之间没有空间.有人知道为什么吗?谢谢 !

我正在创建一个具有扩展和压缩状态的自定义视图 - 在压缩状态下,它只显示一个标签和一个图标,并且在展开状态下,它将在下面显示一条消息.这是截至目前为止它如何工作的截图:

的View本身保存用于测量一次冷凝状态和展开状态的大小值,所以它在使用通常的做法视图时(例如,在一个很简单的两个状态之间进行动画,和LinearLayout)一切按预期工作.视图大小的更改是通过调用完成的getLayoutParams().height = newHeight; requestLayout();
但是,在a中使用它时ListView,视图将被回收并保持其先前的高度.因此,如果视图在隐藏时被展开,那么当它被回收用于下一个列表项时,它将显示为展开.它似乎没有收到另一个布局传递,即使我请求布局ListAdapter.我考虑使用具有两种不同视图类型(扩展和压缩)的回收器,但大小将根据消息的大小而变化.是否有一个事件,我可以听到视图重新附加ListView?或者你有另外一个如何处理这个问题的建议?
编辑:这就是我如何确定视图的扩展和压缩高度:
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if(r - l > 0 && b - t > 0 && dimensionsDirty) {
int widthSpec = MeasureSpec.makeMeasureSpec(r - l, MeasureSpec.EXACTLY);
messageView.setVisibility(GONE);
measure(widthSpec, MeasureSpec.UNSPECIFIED);
condensedHeight = getMeasuredHeight();
messageView.setVisibility(VISIBLE);
measure(widthSpec, MeasureSpec.UNSPECIFIED);
expandedHeight = getMeasuredHeight();
dimensionsDirty = false;
}
}
Run Code Online (Sandbox Code Playgroud) 所以昨天我正在编程,突然我setTitle在WindowManager.LayoutParams课堂上遇到了这个方法,为什么这个类有这样的setTitle方法呢?在哪里使用?该文档没有说明该功能.
我的猜测是,它可以用于调试或类似的东西,但除此之外,我没有线索.
为什么它会被宣布为最终方法?因为我们尚未准备好覆盖它?
就是想...
注意:以下两个答案都是"正确"并提供良好信息的一些方法,但只能接受一个.
我想改变我Listview的位于我的宽度和高度DrawerLayout:
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout.LayoutParams myParam = new DrawerLayout.LayoutParams(20, 20);
mDrawerList.setLayoutParams(myParam);
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
06-21 09:30:57.361: E/AndroidRuntime(12583): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jk.demo/com.jk.demo.MemoStart}:
java.lang.IllegalArgumentException: View android.widget.ListView{414506a8 VFED.VC. ......I. 0,0-0,0 #7f04003a app:id/left_drawer} is not a sliding drawer
Run Code Online (Sandbox Code Playgroud)
drawer_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/left_drawer"
android:layout_width="540dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
Run Code Online (Sandbox Code Playgroud)
我导入:
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.LayoutParams;
Run Code Online (Sandbox Code Playgroud)
有解决方案吗
如果我想用Java以编程方式设置ImageView的宽度/高度,如下所示:
image_view.getLayoutParams().width = 200;
Run Code Online (Sandbox Code Playgroud)
那些"200"的单位是多少?是px/dp吗?
它在每台设备上看起来都"一样"吗?(这意味着:它在平板电脑上是非常大的,在智能手机上是非常小的吗?)
对于我的应用程序,我必须在android屏幕底部的导航栏顶部绘制一个位图.我很想知道WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY是否可用于覆盖导航栏?
我LayoutParams cannot be resolved to a variable在一行代码上得到错误,如下所示tv.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f));
当我按ctrl + shift + o导入必要的pacakges我得到了很多版本的包作为选项.我很困惑哪一个应该做这个工作.
这是我得到的选项
导入后import android.app.ActionBar.LayoutParams;仍然出错
The constructor AbsListView.LayoutParams(int, int, float) is undefined
Run Code Online (Sandbox Code Playgroud) 是否可以禁用片段中的屏幕捕获?我知道以下适用于Activity类
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我有一个显示在活动之上的片段,该怎么办?我可以以某种方式禁用屏幕捕获?我试图在片段的onCreate()或onCreateView()方法中设置FLAG_SECURE,但它不起作用.我仍然可以拍摄屏幕截图.只有当我在父活动中添加标志时,我才能禁用它.
在相关的说明中,比方说,我在ParentActivity.java中有一个方法(扩展了Activity)
public void disableScreenCapture() {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
}
Run Code Online (Sandbox Code Playgroud)
在我的ChildFragment.java中(扩展了Fragment)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ParentActivity parentActivity = (ParentActivity)getActivity();
parentActivity.disableScreenCapture(); //doesn't work
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ParentActivity parentActivity = (ParentActivity)getActivity();
parentActivity.disableScreenCapture(); //doesn't work either
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
提前致谢
I am creating app in which there is screen with searchBar by this lib. My activity layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<TextView
android:id="@+id/title"
android:textColor="@color/colorPrimary"
android:text="@string/mainScreenTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAlignment="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:paddingTop="100dp"/>
<com.arlib.floatingsearchview.FloatingSearchView
android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="100dp"
android:animateLayoutChanges="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title"/>
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
There i have to move FloatingSearchingView to top of screen and change height to for example 500dp - like this:
app:layout_constraintTop_toTopOf="parent"
android:layout_height="500dp"
Run Code Online (Sandbox Code Playgroud)
And later …
layoutparams ×10
android ×9
animation ×1
button ×1
drawerlayout ×1
java ×1
listview ×1
resolve ×1
screenshot ×1
width ×1