【问题标题】:Circular image in imageview from it's IDimageview 中的圆形图像,来自它的 ID
【发布时间】:2015-09-01 08:01:25
【问题描述】:

我需要将我从数据库中获取的图像制作成圆形

我已经制作了这段代码,但我不知道如何完成它以使图像成为圆形

请帮忙

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);

}

这是 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>

我觉得我需要做一个样式

我尝试这样做,但失败了

请帮忙

【问题讨论】:

标签: android xml imageview


【解决方案1】:

你需要来自CircularImageView的CircularImageView

在 xml 文件中,您必须替换此代码而不是 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" />

在活动文件中替换此代码而不是 Imageview:-

CircleImageView im= (CircleImageView) findViewById(R.id.img_car);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多