I have a android.graphics.Path variable which I want to convert into an ImageView in my activity. What I do right now and does NOT work (but it does run without error, it just displays a blank activity) is:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Path p = ... // some bezier curves PathShape pathShape = new PathShape(path, (float)20.0, (float)20.0); ShapeDrawable shapeDrawable = new ShapeDrawable(pathShape); ImageView testImage = (ImageView) findViewById(R.id.testImage); testImage.setImageDrawable(shapeDrawable); } } The corresponding activity_main.xml is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.tg.MindGames.set.MainActivity">
<ImageView android:id="@+id/testImage" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
What did I do wrong and what is considered best practice to put Path into an ImageView?
Additional Information: I want to use the Paths to draw the images of cards in a simple card game. Several cards and additional text fields should be displayed on the activity at the same time, cards should be able to have an onClickListener. The size of 20.0 x 20.0 is arbitrary and should be altered later when I use the ImageViews in a GridView.