我有一个线性布局,包括imageview和textview,一个在线性布局下面.
<LinearLayout android:orientation="horizontal" ... >
<ImageView
android:id="@+id/thumbnail"
android:layout_weight="0.8"
android:layout_width="0dip"
android:layout_height="fill_parent">
</ImageView>
<TextView
android:id="@+id/description"
android:layout_weight="0.2"
android:layout_width="0dip"
android:layout_height="wrap_content">
</TextView>
Run Code Online (Sandbox Code Playgroud)
可能缺少一些规则,这是为了给出一个想法,布局看起来如何.我希望另一个小文本视图说50dip的长度和宽度,放在imageview上,"over"我的意思是z-index比imageview更多,我想把它放在imageview的中心和上面(重叠).
我想知道如何将一个视图放在另一个视图上方,具有不同的z-index(最好是线性布局)?
为root studio传递null给了我这个警告:
避免将null作为视图根传递(需要解析膨胀布局的根元素上的布局参数)
它显示为空值getGroupView.请帮忙.
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
super();
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我正试图在Android上的ActionBar上做一些事情.
我已经在操作栏的右侧添加了新项目.
如何更改操作栏的左侧?我想更改图标和文本,我想在操作栏中为其他屏幕添加"后退按钮"

我有一个用XML定义的布局.它还包含:
<RelativeLayout
android:id="@+id/item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)
我想用其他XML布局文件来扩充这个RelativeView.我可能会根据情况使用不同的布局.我该怎么办?我正在尝试不同的变化
RelativeLayout item = (RelativeLayout) findViewById(R.id.item);
item.inflate(...)
Run Code Online (Sandbox Code Playgroud)
但他们都没有做好.
我希望有一个带有按钮的2x2网格.这只是ICS所以我试图使用给定的新GridLayout.
这是我的布局的XML:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/favorites_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00"
android:rowCount="2"
android:columnCount="2">
<Button
android:text="Cell 0"
android:layout_row="0"
android:layout_column="0"
android:textSize="14dip" />
<Button
android:text="Cell 1"
android:layout_row="0"
android:layout_column="1"
android:textSize="14dip" />
<Button
android:text="Cell 2"
android:layout_row="1"
android:layout_column="0"
android:textSize="14dip" />
<Button
android:text="Cell 3"
android:layout_row="1"
android:layout_column="1"
android:textSize="14dip" />
</GridLayout>
Run Code Online (Sandbox Code Playgroud)
问题是我的视图不能均匀地拉伸到每一行.这会在GridLayout的右侧产生大量额外空间.
我试过设置,layout_gravity="fill_horizontal"但只适用于行的最后一个视图.这意味着Cell 1一直延伸为Cell 0提供足够的空间.
关于如何解决这个问题的想法?
我可以android:gravity="bottom|center_horizontal"在textview上使用xml来获得我想要的结果,但我需要以编程方式执行此操作.我的文本视图tablerow位于一个内容中relativelayout.
我试过了:
LayoutParams layoutParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
labelTV.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)
但是,如果我理解正确,那将适用于tablerow,而不是textview?
这是XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/LightStyle"
android:layout_width="fill_parent"
android:layout_height="55dip"
android:clickable="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
如何以style编程方式设置属性?
我对ConstraintLayout和RelativeLayout之间的区别感到困惑.有人可以告诉我他们之间的确切差异吗?
android android-layout android-relativelayout android-constraintlayout
是否可以在运行时创建RelativeLayout来以android:layout_below编程方式设置等效项?
我有一个自定义视图,可以将可滚动的位图绘制到屏幕上.为了初始化它,我需要传递父布局对象的像素大小.但是在onCreate和onResume函数期间,尚未绘制布局,因此layout.getMeasuredHeight()返回0.
作为一种解决方法,我添加了一个处理程序等待一秒然后测量.这是有效的,但它很草率,我不知道在布局绘制之前我能在多长时间内缩短时间.
我想知道的是,如何检测布局何时被绘制?有事件或回调吗?