为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) 该LayoutInflater.inflate文档是不看好的目的十分清楚我的attachToRoot参数.
attachToRoot:膨胀的层次结构是否应附加到根参数?如果为false,则root仅用于为XML中的根视图创建LayoutParams的正确子类.
有人可以更详细地解释,特别是根视图是什么,并且可能显示一个行为true和false值之间的变化的例子?
对不起,巨大的代码转储,但我真的迷路了.
MyActivity.java onCreate:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_singlepane_empty);
mFragment = new PlacesFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.root_container, mFragment)
.commit();
Run Code Online (Sandbox Code Playgroud)
PlacesFragment.java onCreateView:
mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null);
return mRootView;
Run Code Online (Sandbox Code Playgroud)
注意:mRootView是一个ViewGroup全局,我相信没问题.PlacesFragment是一个ListFragment.
布局:
activity_singlepane_empty.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00f">
<include layout="@layout/actionbar"/>
<!-- FRAGMENTS COME HERE! See match_parent above -->
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
list_content.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listContainer"
android:background="#990"
>
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
<TextView android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/no_data_suggest_connection"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
问题:正如您所看到的,预期的行为是将上面的空TextView显示在屏幕中心.在Eclipse的设计预览中,没关系.只有当作为片段添加到root_view时,FrameLayout才会填满整个屏幕.
root_container为蓝色,FrameLayout为黄色,请参阅下面的调试目的.黄色窗格不应该填满整个屏幕吗?!?!?!?

android center fragment android-linearlayout android-framelayout
这应该是一件非常容易的事情,但它看起来非常棘手.在我的代码中我有这个ListView:
<ListView android:id="@+id/sums_list" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_weight="1" android:dividerHeight="0dp"></ListView>
Run Code Online (Sandbox Code Playgroud)
这是使用使用此视图的ArrayAdapter填充的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdpb="http://schemas.android.com/apk/res/ale.android.brainfitness"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="55dp">
...
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
为什么55dp项目不高?
谢谢大家
我有两个布局:main.xml和buttonpanel.xml.在buttonpanel.xml中,在main linearlayout中,我将gravity设置为bottom.现在我尝试使用以下代码添加按钮面板布局.
setContentView(R.layout.main);
LinearLayout layout=(LinearLayout)findViewById(R.id.mainlinearlayout);
LayoutInflater inflater= (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.buttonpanel,null);
layout.addView(view);
Run Code Online (Sandbox Code Playgroud)
我的问题是面板被添加到顶部,虽然我已经在buttonpanel.xml中将重力设置为底部.如果我使用include将buttonpanel.xml添加到main.xml,它可以正常工作.
任何人都可以帮我解决我的代码有什么问题吗?
我设计了一个带有地图片段和recyclerView的布局.每个recyclerView项都是cardview(我已指定给出xml布局).
问题是RecyclerView项目没有填充屏幕宽度. img在这里
我试图将layout_width更改为fill_parent,match_parent但它无能为力
这是每个项目的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:id="@+id/cardView">
<LinearLayout
android:id="@+id/locationItemView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="120px"
android:layout_height="120px"
android:id="@+id/imgIcon"
android:background="@drawable/image_bg"
android:layout_margin="5dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
<LinearLayout
android:id="@+id/layoutInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Location Name"
android:textColor="#d5c645"
android:textStyle="bold"
android:textSize="20dp"
android:padding="3dp" />
<TextView
android:id="@+id/txtAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Location Address"
android:textSize="16dp"
android:padding="3dp" />
<TextView
android:id="@+id/txtDistance"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="Location Distance"
android:textSize="14dp"
android:textStyle="italic"
android:padding="2dp"
android:textAlignment="viewEnd" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
和main_layout
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我正在处理的应用程序需要一个动态布局,显示配置文件的HorizontalScrollView.配置文件只是一个带有图片和一些文本的RelativeLayout.由于我从数据文件中获取数据,因此我需要为每个配置文件创建一个相对布局.首先,我在for循环中以编程方式创建了每个RelativeLayout,然后将其添加到父视图中.这有效,但我不想这样做.我想根据设备的屏幕尺寸等使用不同的布局文件.
然后我想.好吧,如果我的布局上只有一个配置文件怎么办?我的代码可以获得一个配置文件,findViewById()然后根据它创建新的配置文件!换一种说法:
// get the layout
profileLayout = (LinearLayout) findViewById(R.id.profileLayout);
// get the first profile in the layout
originalProfile = (RelativeLayout) findViewById(R.id.profile1);
// make copy of profile
temporaryProfile = originalProfile;
// make changes to the this profile and add it back
profileLayout.addView(temporaryProfile);
Run Code Online (Sandbox Code Playgroud)
当然,这不起作用,因为这是java,而temporaryProfile现在是对originalProfile的引用.那么有没有办法复制这个RelativeLayout?我知道LayoutInflater,但我仍然不明白它是如何工作的.还有Object.clone().
我试图设置我的AlertDialog样式,我已经能够通过样式和xml声明更改大部分内容......但仍然存在一些问题:

这是我在RootActivity中的功能(我的活动扩展了这个)
public static void showNoConnectionDialog(Context ctx1) {
final Context ctx = ctx1;
LayoutInflater factory = LayoutInflater.from(ctx);
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(ctx, R.style.SetdartDialog));
builder.setView(factory.inflate(R.layout.alert_dialog, null))
.setIcon(R.drawable.icon)
.setCancelable(true)
.setMessage(R.string.check_wireless_settings)
.setTitle(R.string.no_connection)
.setPositiveButton(R.string.myes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
})
.setNegativeButton(R.string.mno, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
return;
}
})
.show();
}
Run Code Online (Sandbox Code Playgroud)
这里是styles.xml的一个片段
<?xml version="1.0" encoding="utf-8"?>
<resources> …Run Code Online (Sandbox Code Playgroud) 我有一个内部布局和SurfaceTexture视频流的对话框.当我收到视频width和height视频时,我会调整我的布局:
private void resizeView(final VideoFormatInfo info) {
final Size size = calculateSize(info.getWidth(), info.getHeight());
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
final ViewGroup.LayoutParams layoutParams = mInnerLayout.getLayoutParams();
layoutParams.width = size.x;
layoutParams.height = size.y;
Log.i(TAG, String.format("run: setting innerlayout bounds to %d,%d", size.x, size.y));
mInnerLayout.setLayoutParams(layoutParams);
}
});
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个全屏按钮,应该将布局调整到整个屏幕.但是当我按下它时,布局仍然在屏幕的一个小区域内.
当我检查日志中正确的值size.x和size.y是否(屏幕的边界),但布局没有正确调整大小.
innerlayout被添加到名为"VideoPlayer"的customView中.我将视频播放器背景的颜色设置为红色,因此当我切换到全屏时,整个屏幕变为红色,除了中间的视频流.这意味着底层视图正在适当调整大小,但innerLayout不是出于某种原因.
有趣的是,我在视频渲染上有另一种布局,可以创建"闪光效果"来模拟拍摄快照时的相机闪光.触发该闪光效果后,视频将调整为整个屏幕.
所以这是我的布局树:
VideoPlayerView (CustomView, not VideoView)
innerLayout (RelativeLayout)
videoSurfaceTexture (SurfaceTextureView)
flashLayout (RelativeLayout)
Run Code Online (Sandbox Code Playgroud)
我也将其设置为调试:
@Override
public void onSurfaceTextureSizeChanged(final SurfaceTexture surfaceTexture, final int width, …Run Code Online (Sandbox Code Playgroud) 是否可以为ListView设置边距/填充而不将边距应用于标题?我希望我的ListView与Google Now布局一样.除了这个小问题,我已经完成了所有工作.
问题:是否可以不将ListView的布局参数应用于其标题?
EDIT1:更多信息
紫色视图是listView的标题.我已经尝试在列表项布局中添加边距.这也不起作用.我需要的是一种方法,将边距应用于列表视图,以便它不会将边距应用于listView中的标头.
EDIT2:我的布局header.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="@dimen/top_height"
android:background="@color/top_item" />
<View
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="@dimen/sticky_height"
android:layout_gravity="bottom" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
root_list.xml
<LinearLayout>
<com.abhijith.CustomListView
android:id="@android:id/list"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_height="wrap_content" /></LinearLayout>
Run Code Online (Sandbox Code Playgroud)
list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/card_background"
android:orientation="vertical" >
<TextView
android:id="@+id/textview_note"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textview_note_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"/></LinearLayout>
Run Code Online (Sandbox Code Playgroud)
由于这篇文章的篇幅,我已经删除了uselsess布局属性.
