-1

I need to make the image that I get from database circular

I have made this code but I don't know how to complete it to make the image circular

please help

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);
    name = (TextView) findViewById(R.id.names);
    date = (TextView) findViewById(R.id.dates);
    Story = (TextView) findViewById(R.id.story);
    im = (ImageView) findViewById(R.id.img_car);
    im.setScaleType(ImageView.ScaleType.FIT_XY);

    //ScrollView scroller = new ScrollView(this);
    //scroller.addView(Story);
    Bundle extras = getIntent().getExtras();

    int idf = extras.getInt("index");
    Book selectedBook;
    db = new SQLhelper(getApplicationContext());

    // read the book with "id" from the database
    selectedBook = db.readBook(++idf);
    name.setText(selectedBook.getTitle());
    date.setText(selectedBook.getdate());
    Story.setText(selectedBook.getstory()+"\n \n ");

    pname = selectedBook.getTitle();
    test = selectedBook.getimage();   
    int id = getResources().getIdentifier("com.example.tarekhy:drawable/" + test, null, null);  
    im.setImageResource(id);

}

and this is xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:padding="8dp" >
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="8dp" 
    android:background="@drawable/customborder">

<ImageView
    android:id="@+id/img_car"
    android:layout_width="70dp"
    android:layout_height="50dp"
    android:layout_marginBottom="5dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="5dp"
    android:contentDescription="@null"
    android:gravity="center_vertical" 
    android:onClick="viewbig"
    />
    <RelativeLayout
    android:id="@+id/imgs"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

   <LinearLayout
        android:id="@+id/layout_car_model"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/names"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="bold" 
            android:text="gfhbj"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_car_color"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/layout_car_model"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/dates"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="italic" 
           />


    </LinearLayout>

</RelativeLayout>

</LinearLayout>
<ScrollView android:id="@+id/textAreaScroller" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_x="0px" 
android:layout_y="25px" 
android:scrollbars="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/fbedittext"
        android:layout_marginTop="22dp"
        android:id="@+id/story"
        android:textStyle="bold"
        android:layout_marginBottom="20px"
        />
</ScrollView>
"

</LinearLayout>

I think that I need to make a style

I tried to do this but I failed

Help please

Andrew Emad
  • 277
  • 3
  • 13
  • 1
    Have you looked at this library, it seems to do exactly what you need: https://github.com/hdodenhof/CircleImageView – Frank D. Sep 01 '15 at 08:02
  • there is lots of stuff available for making circular images. http://stackoverflow.com/questions/16208365/create-a-circular-image-view-in-android – Meenaxi Sep 01 '15 at 08:03
  • https://github.com/Pkmmte/CircularImageView – Androider Sep 01 '15 at 08:07

1 Answers1

0

You Need CircularImageView From CircularImageView

in xml file You have To Replace this code instead of Imageview :-<de.hdodenhof.circleimageview.CircleImageView android:id ="@+id/img_car" android:layout_width="160dp" android:layout_height="160dp" android:layout_centerInParent="true" app:border_width="2dp" app:border_color="@color/dark" />

In Activity File Replace This Code instead of Imageview:-

CircleImageView im= (CircleImageView) findViewById(R.id.img_car);
Dx Android
  • 61
  • 2
  • 13