I have 2 layouts: activity_main
and activity_car_service
; I created some mipmaps from where I got my images buttons source
When running the app the activity_main
contains all my buttons but when pressing an imageButton
to open the activity_car_service
can not see any of them...
activity_car_service
is declared in manifest, still not see any imageButton
Here is activity_car_service
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:orientation="vertical">
<ImageButton
android:id="@+id/imageButton1111"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:onClick="sendMessage"
android:scaleType="fitCenter"
app:srcCompat="@mipmap/ic_auto_tracting" />
<ImageButton
android:id="@+id/imageButton2111"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_auto_lighting" />
<ImageButton
android:id="@+id/imageButton3111"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitCenter"
app:srcCompat="@mipmap/ic_carservice" />
<ImageButton
android:id="@+id/imageButton34111"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_auto_oil" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:orientation="vertical">
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_auto_brakes" />
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_auto_battery" />
<ImageButton
android:id="@+id/imageButton6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_auto_engine" />
<ImageButton
android:id="@+id/imageButton66"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_auto_brakes" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Here is how I call it:
public class CarServiceSubMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_car_service);
}
}
Manifest:
<activity android:name="utils.CarServiceSubMenu">
android:label = "lala"/>
</activity>
MainActivity:
public void openCarServiceSubMenu(View view)
{
Intent intent = new Intent(MainActivity.this, CarServiceSubMenu.class);
startActivity(intent);
}
activity_main which is working:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.sharmind93.nj00.MainActivity">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:orientation="vertical">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:onClick="sendMessage"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_fire" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_plumbing" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:onClick="openCarServiceSubMenu"
app:srcCompat="@mipmap/ic_carservice" />
<ImageButton
android:id="@+id/imageButton34"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_dentist" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:orientation="vertical">
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_lightning" />
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_hairdress" />
<ImageButton
android:id="@+id/imageButton6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_carwash" />
<ImageButton
android:id="@+id/imageButton66"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="@null"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_misc" />
</LinearLayout>
</RelativeLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/ic_dialog_info"
android:id="@+id/imageButton16"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:layout_centerVertical="false"
android:layout_centerInParent="false"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false" />
</RelativeLayout>
What can be the problem ? I spent so much time to try out different things ...
Please help!
Your ImageButtons have width=match_parent while its parent have width=wrap_content.
Their size is 0.
Change the first LLayout with to match_parent too so you can see then.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
Also,your layout will cover the button, try to use below=button (since you are using RelativeLayout as parent and height=wrap_content
The RelativeLayout can be used for adding constraint like below/onTopof/toRightof other views in the layout, you are overlaping your layout with other views and cant see a thing.
实际上问题是我使用了app:srcCompat,但是我的活动不是AppCompatActivity...。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.