在我的代码中,我有一个具有多个子布局的XML文件.我只想根据设备的屏幕宽度以编程方式设置其中一个子布局的宽度.到目前为止,我已经尝试过Layout params,setparam和其他方法,但它在获取布局ID时显示空指针异常.
我的父布局是相对布局,第一个子布局是线性布局("对于此布局我需要更改宽度")
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/childlayout"
android:layout_width="250dip"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#153746">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/sub_title"
android:gravity="center_vertical" >
<TextView
android:id="@+id/menu_header_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="asd"
android:textColor="#ffffff"
android:layout_marginLeft="10dip" />
<ImageView
android:id="@+id/menu_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<ListView
android:id="@+id/menu_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@android:color/darker_gray"
android:dividerHeight="1dip"
android:scrollingCache="false" />
</LinearLayout>
<FrameLayout
android:id="@+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Java代码: -
public class SlideMenu extends LinearLayout {
// keys for saving/restoring instance state
public final static String KEY_MENUSHOWN = "menuWasShown";
private final static String KEY_STATUSBARHEIGHT = …Run Code Online (Sandbox Code Playgroud) 当用户点击另一个按钮时,我正在尝试扩展Spinner.例如:我有一个带有值的Spinner和一个'OK'按钮,当用户点击'ok'buttton而不从spinner中选择任何值时,Spinner会自行扩展.这是否可以获得一个事件来扩展微调器而无需用户在微调器上进行交互.
我有一个片段,我放置了一个包含三个片段的视图寻呼机,当我借助以下代码从这三个片段中的任何一个打开另一个片段时:
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.content_frame, fragment);
fragment.setRetainInstance(true);
transaction.addToBackStack(null);
transaction.commit();
Run Code Online (Sandbox Code Playgroud)
它像魅力一样打开,但是当我按下后退按钮时,视图寻呼机的一个视图消失了。我尝试了在 stackoverflow 中提到的不同方式,但没有帮助。
第一个片段里面我放置我的 viewPager 代码:
public class Fragment1 extends Fragment implements
OnClickListener {
ICallback callback;
private LinearLayout headerContainer;
private ImageView headerLogo;
private TextView headerName;
private Button menuBarButton;
MyAdapter adapter;
ViewPager pager;
ActionBar actionBar;
private Button progOverview, progStr, bonusPoint;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof ICallback) {
this.callback = (ICallback) activity;
}
actionBar = activity.getActionBar();
actionBar.show();
}
@Override
public View onCreateView(LayoutInflater inflater, …Run Code Online (Sandbox Code Playgroud) android ×3