Android 当我试图画圆圈时,屏幕上没有显示任何内容
这是我的Android 当我试图画圆圈时,屏幕上没有显示任何内容,android,xml,geometry,Android,Xml,Geometry,这是我的main活动文件代码: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Tool
main活动
文件代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
这是我的活动\u main.xml
代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context="com.example.vinaykumar.sample.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
<View android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="@drawable/myfile"/>
</android.support.design.widget.CoordinatorLayout>
上面是文件位置的图像
我的问题是,当我运行程序时,它不会在屏幕上显示任何内容,也不会创建圆。我是android新手,所以我不知道我做错了什么。很抱歉,如果代码太多,但我想如果我显示程序中的所有内容会更清楚。感谢您的帮助 错误: 1) 显示可绘制工具栏的方式不正确 2) 您设计的可绘制文件为您提供了一个椭圆形形状,而不是圆形形状 我的解决方案: 解决方案1)Xml代码: myfile.xml:-
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="1dp"
android:color="#78d9ff"/>
<size
android:width="120dp"
android:height="120dp"/>
</shape>
</item>
</selector>
这是一个太庞大的代码。您正在尝试创建一个圆形Imageview,其中的图像设置为。有很多很好的库可以绘制循环Imageview,只需放置一些xml代码,而不需要执行大量代码。@ShivamSharma不,我不想创建循环Imageview。我只是想画个圆圈。而且,是的,我也尝试只使用xml代码,其余代码在您创建文件时已经为您键入。您是否尝试在工具栏上显示myFile.xml可绘制文件?如果我是对的,那么我有一个解决方案给你。@ShivamSharma我想让圆圈显示在屏幕上。我是android新手,所以我不知道在工具栏上显示意味着什么。首先,你们必须知道什么是appbarlayout,toolbar,actionbar。因为您的代码实际上是试图在工具栏上绘制圆形,所以它与toolbar@Hemlata这是我的荣幸
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="1dp"
android:color="#78d9ff"/>
<size
android:width="120dp"
android:height="120dp"/>
</shape>
</item>
</selector>
<?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">
<View android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:layout_centerInParent="true"
android:background="@drawable/myfile"/>
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="1dp"
android:color="#78d9ff"/>
<size
android:width="120dp"
android:height="120dp"/>
</shape>
</item>
</selector>