I'm trying to make buttons wich would change part of the context, but the match_parent not working propertly.
got java main file:
class public MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
Button bn1 = (Button) findViewById(R.id.navbar_1);
Button bn2 = (Button) findViewById(R.id.navbar_2);
bn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FragmentMeters fr = new FragmentMeters();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.layout_to_replace, fr);
ft.commit();
}
});
bn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FragmentValues fr = new FragmentValues();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.layout_to_replace, fr);
ft.commit();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
Then another java class FragmentMeters (and similar FragmentValues):
public class FragmentMeters extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_meters, null);
return view;
}
}
And main XML, something like this:
<LinearLayout
android:id="@+id/navbar"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="82dp"
android:background="@color/highlighted_text_material_dark"
android:weightSum="4">
<Button
android:id="@+id/navbar_1"
android:text="@string/navbar_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="13sp"
android:background="@android:color/transparent"
android:gravity="bottom|center_horizontal" />
<Button
android:id="@+id/navbar_2"
android:text="@string/navbar_2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="13sp"
android:background="@android:color/transparent"
android:gravity="bottom|center_horizontal" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_to_replace"
android:orientation="horizontal"
android:layout_below="@+id/navbar"
android:layout_width="match_parent"
android:background="@color/dim_foreground_disabled_material_dark"
android:layout_height="82dp"
android:weightSum="4"/>
And I'm trying to replace the LinearLayout (id="layout_to_replace") with this fragment_meters.xml:
<LinearLayout
xmlns:android="http://ift.tt/nIICcg"
android:orientation="horizontal"
android:layout_below="@+id/navbar"
android:layout_width="match_parent"
android:layout_height="82dp"
android:background="@color/dim_foreground_disabled_material_dark"
android:weightSum="4">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="METERS"/>
</LinearLayout>
But I'm getting this:
Instead of matching it parent's width/height.
No comments:
Post a Comment