小编sgd*_*met的帖子

以编程方式从支持库创建GridLayout

在android中,是否可以完全以编程方式从支持库创建GridLayout(即不编写相应的xml)?

我在一个片段(称为PromotionLayoutFragment)中创建我的GridLayout,如下所示:

ViewGroup fragmentView = (ViewGroup)getView(); 
GridLayout gridLayout = new GridLayout(fragmentView.getContext());
gridLayout.setColumnCount(2);
gridLayout.setRowCount(15);
// add views to grid ...
fragmentView.addView(gridLayout);
Run Code Online (Sandbox Code Playgroud)

这在我使用API​​级别14中的GridLayout类时工作正常,但是当我使用支持库(v7-r9)中的GridLayout时,我得到:

08-10 15:54:52.209: ERROR/AndroidRuntime(14687): FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:255)
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:274)
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:282)
    at net.link.redbutton.fragment.PromotionLayoutFragment.showPromotions(PromotionLayoutFragment.java:168)
    at net.link.redbutton.fragment.PromotionLayoutFragment.onImageResult(PromotionLayoutFragment.java:222)
    at net.link.redbutton.fragment.SchedulerResponseFragment$1.onReceiveResult(SchedulerResponseFragment.java:37)
    at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4441)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

android grid-layout

8
推荐指数
1
解决办法
4142
查看次数

方向更改后不会重新添加片段

旋转设备时,我的应用中的片段不会重新添加到活动的视图中.如果我正确理解文档(以及SO上的类似问题),这应该是片段管理器处理(不必在我的清单中指定android:configChanges).

我的活动看起来像:

public class MainActivity extends SherlockFragmentActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        if (savedInstanceState == null){
            getSupportFragmentManager().beginTransaction()
                .add(R.id.main_fragment_placeholder, new DashboardFragment(),"dashboard")
                .commit();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

片段看起来像(为了清楚起见,省略了clicklisteners等):

public class DashboardFragment extends SherlockFragment {
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
    }
}
Run Code Online (Sandbox Code Playgroud)

布局文件看起来像(activity_main.xml):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:id="@+id/main.main">

    <FrameLayout android:id="@+id/main_fragment_placeholder"
             android:layout_height="fill_parent"
             android:layout_weight="1"
             android:layout_width="0px"
             />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

和fragment_layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main.wrapper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <my.layout.DashboardLayout
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:id="@+id/main.dashboard">
    <!-- some buttons here -->
    </my.layout.DashboardLayout> …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-orientation

2
推荐指数
1
解决办法
5449
查看次数

如何开发修改现有页面的magento扩展?

我需要开发一个magento扩展,它将一些内容添加到特定页面,例如产品视图页面.更具体地说,在产品页面上,需要添加按钮/链接以将产品添加到第三方愿望清单站点.

现在我做了一些研究,并不完全清楚最好的方法是什么:

  1. 使用事件/观察者拦截'core_block_abstract_to_html_after'事件并在需要时添加我的html
  2. 在app/design/frontend/base/default/layout /中使用local.xml,使用'reference'或'update'标签在正确的页面上添加我的块.但是,我可以将此local.xml打包到我的扩展中吗?如果是这样,它是否会覆盖用户自己的local.xml.
  3. 使用Magento Widgets?看起来需要手动将小部件添加到管理CMS面板中的页面,而在管理配置中有一个开关可以禁用或启用包含额外内容.

理想情况下,扩展的用户需要进行最小配置(或XML编辑),并且扩展必须与现有布局或用户完成的修改兼容.

magento

0
推荐指数
1
解决办法
941
查看次数