我一直在尝试了几天,现在让我的布局更有效率使用的几个层次转换嵌套LinearLayouts一个RelativeLayout和所遇到的一些问题,我的天堂没有能够找到一个解决方法...
我搜索了Android初学者小组和这个网站,但却找不到任何可以帮我解决问题的方法.
我在其中一个博客上看到,您可以将布局与合并和包含标签结合起来.所以我拥有一个带有RelativeLayout根元素的主布局文件.在其中我有5个包含标签,它们引用了5个不同的xml布局文件,每个文件都有一个根的合并元素(我的所有合并文件都是相同的,除了它们中的ID).
我遇到了两个问题,我将在发布布局代码的简化版后解释:
示例主布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/translucent_gray" >
<include
android:id="@+id/running_gallery_layout_id"
layout="@layout/running_gallery_layout" />
<include
android:id="@+id/recent_gallery_layout_id"
layout="@layout/recent_gallery_layout"
android:layout_below="@id/running_gallery_layout_id" />
<include
android:id="@+id/service_gallery_layout_id"
layout="@layout/service_gallery_layout"
android:layout_below="@id/recent_gallery_layout_id" />
<include
android:id="@+id/process_gallery_layout_id"
layout="@layout/process_gallery_layout"
android:layout_below="@id/service_gallery_layout_id" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
示例包括合并文件:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
style="@style/TitleText"
android:id="@+id/service_gallery_title_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="@string/service_title" />
<Gallery
android:id="@+id/service_gallery_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="@id/service_gallery_title_text_id" />
<TextView
style="@style/SubTitleText"
android:id="@+id/service_gallery_current_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/service_gallery_title_text_id"
android:layout_above="@id/service_gallery_id" />
</merge>
Run Code Online (Sandbox Code Playgroud)
我遇到两个问题:
1)android:layout_*在include标记中使用时,似乎忽略了属性,并且所有合并的布局都显示在彼此之上.根据这篇文章(http://developer.android.com/resources/articles/layout-tricks-reuse.html)"任何android:layout_*属性都可以与<include /> …
我在App Widget中使用ProgressBar遇到了一个有趣的情况......文档(http://developer.android.com/guide/topics/appwidgets/index.html)说ProgressBar是一个受支持的widget类. .
我没有问题让ProgressBar显示在我的App Widget中,但问题是我希望它只在后台处理发生时显示为用户的视觉反馈.
在ImageViews上我通过RemoteViews.setViewVisibility()完成此操作,一切正常.但是,使用ProgressBar,我得到一个异常,说ProgressBar不能使用此方法.
这是故意还是这个错误?有没有办法解决这个问题?
我编写了一些代码来实现Gallery小部件的垂直滑动.它在Android 1.5和1.6中运行良好但在Android 2.2中不起作用(我还没有尝试使用2.1).
public class SwipeUpDetector extends SimpleOnGestureListener
implements OnTouchListener
{
private GestureDetector m_detector;
public SwipeUpDetector()
{
m_detector = new GestureDetector(m_context, this);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
if (Math.abs(e1.getX() - e2.getX()) < s_swipeMaxOffPath &&
e1.getY() - e2.getY() >= s_swipeMinDistance &&
Math.abs(velocityY) >= s_swipeMinVelocity)
{
int pos = m_gallery.pointToPosition((int)e1.getX(), (int)e2.getY());
startAnimation(pos);
return true;
}
return false;
}
@Override
public boolean onTouch(View v, MotionEvent event)
{
return m_detector == null ? false : m_detector.onTouchEvent(event); …Run Code Online (Sandbox Code Playgroud) 好吧,所以我写了一个ExpandableListView和子类BaseExpandableListAdapter ...一切正常,但我无法让孩子的视图在点击时获得焦点.如果我使用轨迹球一切正常.但如果我试图点击一个孩子,我得不到任何反馈.
我已经尝试设置android:focusable,android:focusableInTouchMode和android:clickable(我也试过通过代码设置这个),但我无法得到任何工作.有任何想法吗?
这是我的适配器代码:
public class ExpandableAppAdapter extends BaseExpandableListAdapter
{
private PackageManager m_pkgMgr;
private Context m_context;
private List<ApplicationInfo> m_groups;
private List<List<ComponentName>> m_children;
public ExpandableAppAdapter(Context context, List<ApplicationInfo> groups, List<List<ComponentName>> children)
{
m_context = context;
m_pkgMgr = m_context.getPackageManager();
m_groups = groups;
m_children = children;
}
@Override
public Object getChild(int groupPos, int childPos)
{
return m_children.get(groupPos).get(childPos);
}
@Override
public long getChildId(int groupPos, int childPos)
{
return childPos;
}
@Override
public int getChildrenCount(int groupPos)
{
return m_children.get(groupPos).size();
}
@Override
public View getChildView(int groupPos, int …Run Code Online (Sandbox Code Playgroud) 我以前使用过ImageView,并了解可以设置的不同比例类型......但是我在使用ListActivity或ExpandableListActivity的行中正确地缩放ImageView时遇到了非常困难的时间.
我已经尝试将android:scaleType属性设置为每个值,但图像从不缩小.我也设置了最小和最大尺寸,它们似乎没有任何效果.我已经在XMl和代码中完成了这两件事但无济于事......
有没有人有任何想法或解决方法?
提前致谢!
编辑:这是ExpandableListView中组行的XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip"
>
<ImageView
android:id="@+id/item_selection_icon_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginLeft="30dp"
android:minWidth="10dp"
android:minHeight="10dp"
android:maxWidth="10dp"
android:maxHeight="10dp"
android:scaleType="centerInside"
/>
<!-- App Name -->
<TextView
android:id="@+id/item_app_name_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/item_selection_icon_id"
android:layout_alignBaseline="@id/item_selection_icon_id"
android:textStyle="normal|bold"
android:textSize="24sp"
/>
<!-- Package Information -->
<TextView
android:id="@+id/item_app_pkg_name_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/item_app_name_id"
android:layout_toRightOf="@id/item_selection_icon_id"
android:layout_weight="2"
android:textStyle="italic"
android:textSize="12sp"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)